第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

當(dāng)您知道文件類型但不知道名稱時,如何從 Azure Data Lake 下載文件?

當(dāng)您知道文件類型但不知道名稱時,如何從 Azure Data Lake 下載文件?

有只小跳蛙 2023-10-18 16:13:15
我可以運行以下命令來下載文件“some/path/known_name.json”def download_file():    try:        file_system_client = FileSystemClient.from_connection_string(...)        full_file_location = "some/path/known_name.json"        target_file_client = file_system_client.get_file_client(full_file_location)        download=target_file_client.download_file()        downloaded_bytes = download.readall()        local_file = open('my_file.json','wb')        local_file.write(downloaded_bytes)        local_file.close()    except Exception as e:        print(e)我的問題是:當(dāng)文件名未知但文件類型已知(例如“ different/path/xxx.json”)時,如何從其他路徑下載
查看完整描述

1 回答

?
UYOU

TA貢獻(xiàn)1878條經(jīng)驗 獲得超4個贊

您可以列出容器中的 blob,然后按 .json 擴展名過濾 json 文件blob.name。

這是我的測試容器中的 blob:

https://img1.sycdn.imooc.com/652f93d7000188b502470218.jpg

這是我的Python代碼:


import os, uuid

from azure.storage.blob import BlobServiceClient, BlobClient, ContainerClient


try:

    # environment variable into account.

    connect_str = os.getenv('AZURE_STORAGE_CONNECTION_STRING')


    # Create the BlobServiceClient object which will be used to create a container client

    blob_service_client = BlobServiceClient.from_connection_string(connect_str)


    # Create a unique name for the container

    container_name = "test"     


    # Create the container

    container_client = blob_service_client.get_container_client(container_name)


    # List the blobs in the container

    local_path = "./data"

    blob_list = container_client.list_blobs()

    for blob in blob_list:

        if('.json' in blob.name) :

            local_file_name = blob.name

            blob_client = blob_service_client.get_blob_client(container=container_name, blob=local_file_name)

            download_file_path = os.path.join(local_path, local_file_name)

            print("\nDownloading blob to \n\t" + local_path)

        

            with open(download_file_path, "wb") as download_file:

                download_file.write(blob_client.download_blob().readall())

            print("\t" + blob.name)


except Exception as ex:

    print('Exception:')

    print(ex)


當(dāng)我運行代碼時,它將下載data.json和data2.json.

https://img1.sycdn.imooc.com/652f93e40001db3301760151.jpg

查看完整回答
反對 回復(fù) 2023-10-18
  • 1 回答
  • 0 關(guān)注
  • 138 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號