【问题标题】:How to read a file from Azure Blob Container using Python如何使用 Python 从 Azure Blob 容器中读取文件
【发布时间】:2025-12-05 06:50:01
【问题描述】:

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

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

谢谢

【问题讨论】:

  • 请编辑您的问题并包含您编写的代码并提及您遇到的任何问题。还包括您正在使用的 SDK 版本。
  • @Dave 你想知道如何使用 python 从 Azure blob 下载文件吗?

标签: python json azure file readfile


【解决方案1】:

如果你想用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

更多详情请参考document

【讨论】: