Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/320.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
Google云存储Python列表\u blob()不打印对象列表_Python_Google App Engine_Google Cloud Storage_Google Cloud Platform_Google Cloud Python - Fatal编程技术网

Google云存储Python列表\u blob()不打印对象列表

Google云存储Python列表\u blob()不打印对象列表,python,google-app-engine,google-cloud-storage,google-cloud-platform,google-cloud-python,Python,Google App Engine,Google Cloud Storage,Google Cloud Platform,Google Cloud Python,我是Python和Google云存储新手。 我正在编写一个python脚本,使用Google Cloud python客户端库从Google Cloud Storage bucket获取文件列表,bucket类中的list_blobs()函数并没有像我预期的那样工作 以下是我的python代码: from google.cloud import storage from google.cloud.storage import Blob client = storage.Client.from

我是Python和Google云存储新手。 我正在编写一个python脚本,使用Google Cloud python客户端库从Google Cloud Storage bucket获取文件列表,bucket类中的list_blobs()函数并没有像我预期的那样工作

以下是我的python代码:

from google.cloud import storage
from google.cloud.storage import Blob

client = storage.Client.from_service_account_json(service_account_json_key_path, project_id)
bucket = client.get_bucket(bucket_id)
print(bucket.list_blobs())
如果我正确理解了文档,print(bucket.list_blobs())应该像这样打印:['testfile.txt','testfile2.txt']

但是,我的脚本打印了以下内容: “google.cloud.storage.bucket.\u位于0x7fdbcac590的BlobIterator对象”

delete_blob()文档的示例代码与我的相同。

我不确定我在这里做错了什么。
如有任何提示/示例/答案,将不胜感激。谢谢

如果您:

for blob in bucket.list_blobs():
    print(blob)
    print(blob.name)

示例列表函数:

def list_blobs(bucket_name):
    """Lists all the blobs in the bucket."""
    storage_client = storage.Client()
    bucket = storage_client.get_bucket(bucket_name)

    blobs = bucket.list_blobs()

    for blob in blobs:
        print(blob.name)

我犯了一个错误,将“prefix”参数与前导正斜杠一起使用,这很快表明它不需要前导正斜杠,谢谢!