简体   繁体   中英

azure - list containers in python

I'm trying to list the containers under an azure account using the python sdk - why do I get the following?

>>> azure.storage.blob.baseblobservice.BaseBlobService(account_name='x', account_key='x').list_containers()
>>> <azure.storage.models.ListGenerator at 0x7f7cf935fa58>

Surely the above is a call to the function and not a reference to the function itself.

you get the following according to source code it return ListGenerator(resp, self._list_containers, (), kwargs)

you can access what you want as follow:

>>>blob_service=azure.storage.blob.baseblobservice.BaseBlobService(account_name='x', account_key='x')
>>>containers = blob_service.list_containers() 
>>>for c in containers: 
      print c.name

for python 3 and more recent distribution of azure libraries, you can do:

from azure.storage.blob import BlockBlobService

block_blob_service = BlockBlobService(account_name=account_name, account_key=account_key) 
containers = block_blob_service.list_containers()
for c in containers: 
   print(c.name)

According to source code

You can access the containers in the storage account by using the snippet below:

from azure.storage.blob.baseblobservice import BaseBlobService

blob_service = BaseBlobService(account_name='<your account name>', account_key='<your account key>')
containers = blob_service.list_containers() 
for container in containers: 
    print ("Container name: {}".format(container.name))

more info on setting up account name and account key visit link

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM