How can I read a text file from Azure blob storage directly without downloading it to a local file(using python)?

独自空忆成欢 提交于 2019-12-08 06:44:26

问题


How can i reads a text blob in Azure without downloading it? I am able to download the file and then read it but, i prefer it to be read without downloading.

print("\nList blobs in the container")
generator = block_blob_service.list_blobs(container_name)                  
for blob1 in generator:
    print("\t Blob name: " + blob.name)

Is there any operation in 'blob1' object, which would allow me to read the text file directly.(like blob1.read or blob1.text or something like this)?


回答1:


You can use get_blob_to_text method.

block_blob_service = BlockBlobService(account_name='myaccount', account_key='mykey')

blob = block_blob_service.get_blob_to_text('mycontainer', 'myblockblob')
print blob.content


来源:https://stackoverflow.com/questions/52530300/how-can-i-read-a-text-file-from-azure-blob-storage-directly-without-downloading

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!