2

如果这个问题以前在其他地方被问过或回答过,我深表歉意。我找不到它。

我对 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 模块 - 那么我也希望有一个链接。

感谢您的时间。

4

1 回答 1

3
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)
于 2018-08-13T15:54:47.140 回答