gpt4 book ai didi

python - 使用python从云存储桶下载文件时如何显示进度条

转载 作者:行者123 更新时间:2023-12-03 17:11:22 26 4
gpt4 key购买 nike

我正在使用下面的 python 代码从云存储桶下载一个 zip 文件

    bucket = storage_client.get_bucket(bucket_name)
blob = bucket.blob(source_blob_name)
print('Downloading file')
blob.download_to_filename(destination_file_name)
print('Download completed')
打印“下载文件”行后如何显示进度条

最佳答案

使用 tqdm 库相当简单。

bucket = storage_client.get_bucket(bucket_name)
blob = bucket.blob(source_blob_name)
with open(destination_file_name, 'wb') as f:
with tqdm.wrapattr(f, "write", total=blob.size) as file_obj:
# blob.download_to_file is deprecated
storage_client.download_blob_to_file(blob, file_obj)

关于python - 使用python从云存储桶下载文件时如何显示进度条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62811608/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com