[英]How to list blob names from 'a' to 'z' in Azure Python SDK?
Currently I have the following to list all of the blobs in my blob container:目前我有以下列出我的 blob 容器中的所有 blob:
blobs = container_client.list_blobs()
However, I am looking for a way to list all of the blobs that start with any of the letters from 'a' to 'z'.但是,我正在寻找一种方法来列出以“a”到“z”中的任何字母开头的所有 blob。 I've read about the name_starts_with parameter, but it seems I can only specify a single letter, rather than a range.
我已经阅读了有关 name_starts_with 参数的信息,但似乎我只能指定一个字母,而不是一个范围。 For example:
例如:
blobs_with_a = container_client.list_blobs(name_starts_with='a')
Is there a way to specify a range of letters that the blob can start with rather than specifying a single character?有没有办法指定blob可以开始的字母范围而不是指定单个字符?
One of the workarounds is to check for the first letter of the blob making sure its ASCII value ranges from 97 to 122. Below is the code that worked for me.一种解决方法是检查 blob 的第一个字母,确保其 ASCII 值范围从 97 到 122。下面是对我有用的代码。
import os
from azure.storage.blob import BlockBlobService
ACCOUNT_NAME = "<STORAGE_ACCOUNT_NAME>"
CONTAINER_NAME = "<CONTAINER>"
SAS_TOKEN='<SAS_TOKEN>'
blob_service = BlockBlobService(account_name=ACCOUNT_NAME,account_key=None,sas_token=SAS_TOKEN)
# Lists All Blobs
print("\nList blobs in the container")
generator = blob_service.list_blobs(CONTAINER_NAME)
for blob in generator:
blobname=blob.name
if(ord(blobname[0])>=97 and ord(blobname[0])<=122):
print(blobname)
SAMPLE RESULTS:样本结果:
Blobs in my storage account我的存储帐户中的 Blob
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.