如何使用 Python 从 Azure Blob 容器读取文件

Dav*_*ave 2 python json file azure readfile

如何使用 Python 读取 Azure blob 容器中的文件?我正在尝试读取容器中的一些 JSON 文件以压平它们。

我是 Azure 新手,对此不太了解。我可以使用“BlobServiceClient”连接到容器。但是,我不确定如何从容器中的文件夹中读取文件

谢谢

Jim*_* Xu 6

如果你想用python从Azure blob读取文件,请参考以下代码

from azure.storage.blob import BlobServiceClient
connection_string=''
blob_service_client = BlobServiceClient.from_connection_string(connection_string)
container_client = blob_service_client.get_container_client("<container name>")
blob_client = container_client.get_blob_client("<blob name>")
blob_client.download_blob().readall() # read blob content as string
Run Code Online (Sandbox Code Playgroud)

更多详情请参考文档