Google Cloud Storage Python list_blob() 不打印对象列表

Google Cloud Storage Python list_blob() not printing object list

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

https://googlecloudplatform.github.io/google-cloud-python/stable/storage-buckets.html

这是我的 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._BlobIterator object at 0x7fdfdbcac590"

delete_blob() 文档中的示例代码与我的相同。 https://googlecloudplatform.github.io/google-cloud-python/stable/storage-buckets.html

我不确定我做错了什么。 任何 pointers/examples/answers 将不胜感激。谢谢!

如果你:

你会看到什么
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)