简体   繁体   中英

Accessing Elements of sqlalchemy orm declarative base class

I am trying to get list of 10 different zip codes closest to a lat/long combination using python's uszipcode( https://github.com/MacHu-GWU/uszipcode-project ) . I cannot get the zipcodes in a list or a dictionary while using the code specified in documentation

>>> 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

I am looking to retrieve/get all the 10 zipcodes in a list where i can access the first zipcode using nearestzip[0] , nearestzip[1]...

不确定您的意思到底是什么,但是您可以仅遍历结果中的项目吗?

nearestzip = [res.zipcode for res in result]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM