这是我在 StackOverflow 上的第一篇文章,希望它尊重这个社区的准则。
我正在尝试用 Python 完成一个简单的任务,因为尽管我对它很陌生,但我发现它非常容易使用。我在Azure上有一个存储帐户,里面有很多容器。每个容器包含一些随机文件和/或 blob。
我想做的是获取所有这些文件和/或 blob 的名称并将其放在文件中。
现在,我到达这里:
import os, uuid
import sys
from azure.storage.blob import BlobServiceClient, BlobClient, ContainerClient, __version__
connection_string = "my_connection_string"
blob_svc = BlobServiceClient.from_connection_string(conn_str=connection_string)
try:
print("Azure Blob Storage v" + __version__ + " - Python quickstart sample")
print("\nListing blobs...")
containers = blob_svc.list_containers()
list_of_blobs = []
for c in containers:
container_client = blob_svc.get_container_client(c)
blob_list = container_client.list_blobs()
for blob in blob_list:
list_of_blobs.append(blob.name)
file_path = 'C:/my/path/to/file/randomfile.txt'
sys.stdout = open(file_path, "w")
print(list_of_blobs)
except Exception as ex:
print('Exception:')
print(ex)
Run Code Online (Sandbox Code Playgroud)
但我有 …