如何在Blob对象中找到键?

时间:2019-01-05 09:37:01

标签: python-3.x google-cloud-platform

我想知道返回的Blob对象中包含哪些 Bucket.list_blobs()

#!/usr/bin/env

from google.cloud import storage

client = storage.Client()

bucket = client.get_bucket("xxx")

blobs = list( bucket.list_blobs() )

for blob in blobs:
    print(blob)

执行上面的代码时,我得到的结果如下。

<Blob: xxx, flights/raw/201501.csv>
<Blob: xxx, flights/raw/201502.csv>
<Blob: xxx, flights/raw/201503.csv>
<Blob: xxx, flights/raw/201504.csv>
<Blob: xxx, flights/raw/201505.csv>
<Blob: xxx, flights/raw/201812.csv>

我已经检查了document,但是 list_blobs 部分未提及有关的信息。我知道sample code中有 blob.name 。但是还有什么,我该如何列出密钥?

我希望字典中有类似keys之类的东西...

1 个答案:

答案 0 :(得分:1)

按照@John Hanly的建议,我能够使用 dir 在对象中看到可用的方法。

代码:

#!/usr/bin/env

from google.cloud import storage

client = storage.Client()

bucket = client.get_bucket("elite-caster-125113")

blobs = list( bucket.list_blobs() )

for blob in blobs:
    print(dir(blob))

现在我可以看到可用的内容。

['_CHUNK_SIZE_MULTIPLE', '_STORAGE_CLASSES', '__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_acl', '_changes', '_chunk_size', '_do_download', '_do_multipart_upload', '_do_resumable_upload', '_do_upload', '_encryption_key', '_get_content_type', '_get_download_url', '_get_transport', '_get_upload_arguments', '_get_writable_metadata', '_initiate_resumable_upload', '_patch_property', '_properties', '_require_client', '_set_properties', 'acl', 'bucket', 'cache_control', 'chunk_size', 'client', 'component_count', 'compose', 'content_disposition', 'content_encoding', 'content_language', 'content_type', 'crc32c', 'create_resumable_upload_session', 'delete', 'download_as_string', 'download_to_file', 'download_to_filename', 'etag', 'event_based_hold', 'exists', 'generate_signed_url', 'generation', 'get_iam_policy', 'id', 'kms_key_name', 'make_private', 'make_public', 'md5_hash', 'media_link', 'metadata', 'metageneration', 'name', 'owner', 'patch', 'path', 'path_helper', 'public_url', 'reload', 'retention_expiration_time', 'rewrite', 'self_link', 'set_iam_policy', 'size', 'storage_class', 'temporary_hold', 'test_iam_permissions', 'time_created', 'time_deleted', 'update', 'update_storage_class', 'updated', 'upload_from_file', 'upload_from_filename', 'upload_from_string', 'user_project']

非常感谢@John Hanley