首页 > 解决方案 > 访问 sqlalchemy orm 声明性基类的元素

问题描述

我正在尝试使用 python 的 uszipcode( https://github.com/MacHu-GWU/uszipcode-project)获取最接近 lat/long 组合的 10 个不同邮政编码的列表。使用文档中指定的代码时,我无法获取列表或字典中的邮政编码

>>> result = search.by_coordinates(39.122229, -77.133578, radius=30, returns=10)

search = SearchEngine(simple_zipcode=True)
result = search.by_coordinates(38.887563, -77.019929, radius=30,returns=10)
for zipcode in result:
nearestzip = zipcode.zipcode
 print(nearestzip) 
#output is list of 10 different zips 
nearestzip 
# output is last zipcode which is 20036 
nearestzip[0]
#output is 2

我正在寻找/获取列表中的所有 10 个邮政编码,我可以使用nearestzip[0]、nearestzip[1] 访问第一个邮政编码...

标签: pythonlistdictionary

解决方案


不确定你的意思,但你可以循环遍历结果中的项目吗?

nearestzip = [res.zipcode for res in result]

推荐阅读