Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/316.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何压缩Google云存储桶中的所有文件?_Python_Zip_Bucket_Cloud Storage - Fatal编程技术网

Python 如何压缩Google云存储桶中的所有文件?

Python 如何压缩Google云存储桶中的所有文件?,python,zip,bucket,cloud-storage,Python,Zip,Bucket,Cloud Storage,我需要压缩给定云存储桶中的所有文件。我已经尝试过几种选择,但到目前为止没有任何效果 目前,我只能检索bucket中的blob,但我还需要生成一个zip文件,将所有这些文件分组,并在bucket中将其置为白色 你能帮我解决这个问题吗 以下是迄今为止的代码: from google.cloud import storage import os os.environ["GOOGLE_APPLICATION_CREDENTIALS"]="file.json"

我需要压缩给定云存储桶中的所有文件。我已经尝试过几种选择,但到目前为止没有任何效果

目前,我只能检索bucket中的blob,但我还需要生成一个zip文件,将所有这些文件分组,并在bucket中将其置为白色

你能帮我解决这个问题吗

以下是迄今为止的代码:

from google.cloud import storage
import os

os.environ["GOOGLE_APPLICATION_CREDENTIALS"]="file.json"

def zip_in_bucket(bucketname):

client = storage.Client()
bucket = client.get_bucket(bucketname)
object_generator = bucket.list_blobs()
for files in object_generator:
    print(files.name)
返回:

file-1.csv
file-2.csv
file-3.csv
file-4.csv
file-5.csv