python-3.x - 获取geojson中列出的几个元素的总和
问题描述
如果这个问题以前在其他地方被问过或回答过,我深表歉意。我找不到它。
我对 python 还是比较陌生,我目前正在设置一个脚本,用于通过 sentinelsat 模块从 ESA 哨兵集线器下载文件。
现在它正在工作,但我希望它有一种打印所涉及的总文件大小的方法。我已经让它打印了所有文件的名称和它们各自的数据大小。我还列出了文件总数。现在我只需要将各个数据大小合计为 1 个值..
所以这是我的代码片段:
print("Listing file name and size:")
print("")
for n in range(0, np.size(bu_images_json["features"])):
print("Image name: ",json.dumps(bu_images_json["features"][n]["properties"]["title"]))
print("File size: ",json.dumps(bu_images_json["features"][n]["properties"]["size"]))
print("Found", n+1, "files availible for download")
print("Total amount to download")
它看起来像这样
Image name: "S2A_OPER_PRD_MSIL1C_PDMC_20161009T061329_R010_V20160727T140022_20160727T140246"
File size: "5.02 GB"
Image name: "S2A_OPER_PRD_MSIL1C_PDMC_20161009T060351_R139_V20160726T142942_20160726T143122"
File size: "5.99 GB"
Image name: "S2A_OPER_PRD_MSIL1C_PDMC_20160720T213054_R053_V20160720T141008_20160720T141008"
File size: "5.65 GB"
Found 131 files availible for download
Total amount to download
如果有人知道任何 github 页面或类似的东西,任何人都玩过并扩展了 sentinelsat 模块 - 那么我也希望有一个链接。
感谢您的时间。
解决方案
from re import sub
print("Listing file name and size:")
total = 0
print("")
for n in range(0, np.size(bu_images_json["features"])):
print("Image name: ",json.dumps(bu_images_json["features"][n]["properties"]["title"]))
print("File size: ",json.dumps(bu_images_json["features"][n]["properties"]["size"]))
total += float(sub('[^0-9.]','',json.dumps(bu_images_json["features"][n]["properties"]["size"])))
print("Found", n+1, "files availible for download")
print("Total amount to download: ",total)
推荐阅读
- javascript - 点击事件函数在整个文档上触发
- python - 如何在 django rest 框架中允许访问基本路由而无需身份验证
- python - 哪个组合触发器导致了 apscheduler 中的作业执行?
- javascript - 跟踪模式(逐行)的结果代码与正常状态下的执行不同
- python - Elasticsearch-python - 带刷新的批量帮助 API
- vue.js - Vuetify + Nuxt:递归目录问题?
- html - 如何正确嵌套 a ?
- python - 为什么在响应 kex-neogitation 时,openssh 服务器会出现一些随机字节?
- docker - GitLab,无法登录 Docker 注册表
- php - 没有传输支持给定的 Messenger DSN