python - 访问 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] 访问第一个邮政编码...
解决方案
不确定你的意思,但你可以循环遍历结果中的项目吗?
nearestzip = [res.zipcode for res in result]
推荐阅读
- python - 比较两列和过滤列与相邻类
- excel - 使用 Office.js 直接获取 Excel 注释单元格引用
- jms - ActiveMQ 显示所有已确认的消息,尽管我只确认了一条
- javascript - 在javascript中遍历嵌套对象数组时的奇怪行为?
- java - 生成 java 类到 src 不仅要使用 maven cxf-codegen-plugin
- java - Grails:Excel 导出 .xlsx 样式问题,打开文件时出现错误消息
- sql-server - 有没有办法创建从 Azure SQL 数据库到 PostgreSQL 的链接服务器?
- python - Tornado 模板调用包括使用变量
- docker - 如何安全地从 GitLab Runner KubernetesExecutor pod 推送到私有容器注册表?
- android - 安装android SDK和下载命令行工具后找不到monkeyrunner文件