本文整理汇总了Python中azure.storage.BlobService.get_blob_to_text方法的典型用法代码示例。如果您正苦于以下问题:Python BlobService.get_blob_to_text方法的具体用法?Python BlobService.get_blob_to_text怎么用?Python BlobService.get_blob_to_text使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类azure.storage.BlobService
的用法示例。
在下文中一共展示了BlobService.get_blob_to_text方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from azure.storage import BlobService [as 别名]
# 或者: from azure.storage.BlobService import get_blob_to_text [as 别名]
class BlobCache:
'''
Simplistic cache toolkit targetting an Azure Blob Service.
name: the name of a storage account.
key: the access key for the storage account.
container: the name of the container to use.
'''
def __init__(self, name, key, container):
self.container = container
self.blobstore = BlobService(name, key)
self.blobstore.create_container(self.container)
def getresponse(self, cachekey):
'''
Get a value from the cache.
cachekey: The key.
Kilroy notes that this throws an exception rather than returning a
value on failure.
'''
return self.blobstore.get_blob_to_text(self.container,str2blobname(cachekey))
def putresponse(self, cachekey, value):
'''
Put a value in the cache with the given key.
cachekey: The key.
value: The value to associate with the key.
'''
return self.blobstore.put_block_blob_from_text(self.container, str2blobname(cachekey), value)
def invalidate(self, cachekey):
'''
Invalidate a value in the cache. Immediate. Permanent.
cachekey: The key.
'''
self.blobstore.delete_blob(self.container, str2blobname(cachekey))
示例2: print
# 需要导入模块: from azure.storage import BlobService [as 别名]
# 或者: from azure.storage.BlobService import get_blob_to_text [as 别名]
blobs = []
marker = None
while True:
batch = blob_service.list_blobs('YourContainer', marker=marker, prefix='input_')
blobs.extend(batch)
if not batch.next_marker:
break
marker = batch.next_marker
for blob in blobs:
print(blob.name)
#read the blob file as a text file
#I just read in the first from the pervious list
data = blob_service.get_blob_to_text('rockt', blobs[0].name).split("\n")
print("Number of lines in CSV " + str(len(data)))
#do your stuff
#I want to filter out some lines of my CSV and only keep those having ABC or DEF in them
matchers = ['abc', 'def']
matching = [s for s in data if any(xs in s for xs in matchers)]
print("Number of lines in CSV " + str(len(matching)))
#write your text directly back to blob storage
blob_service.put_block_blob_from_text(
'YourContainer',
'YourOutputFile.csv',
''.join(matching),
示例3: gettextobjectfromazure
# 需要导入模块: from azure.storage import BlobService [as 别名]
# 或者: from azure.storage.BlobService import get_blob_to_text [as 别名]
def gettextobjectfromazure (strkey):
blob_service = BlobService(account_name='wanderight', account_key='gdmZeJOCx3HYlFPZZukUhHAfeGAu4cfHWGQZc3+HIpkBHjlznUDjhXMl5HWh5MgbjpJF09ZxRaET1JVF9S2MWQ==')
return blob_service.get_blob_to_text(config['container'], strkey)