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

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

使用Python API從Google Cloud Datalab將文件上傳到

使用Python API從Google Cloud Datalab將文件上傳到

米琪卡哇伊 2022-08-16 18:44:14
我正在嘗試使用Python API將文件從筆記本本身內(nèi)的Datalab實(shí)例上傳到我的Google存儲(chǔ)桶,但我無法弄清楚。Google在其文檔中提供的代碼示例似乎不適用于Datalab。我目前正在使用gsutil命令,但想了解如何在使用Python API時(shí)執(zhí)行此操作。文件目錄(我想上傳位于檢查點(diǎn)文件夾中的python文件):!ls -R.:checkpoints  README.md  tpot_model.ipynb./checkpoints:pipeline_2020.02.29_00-22-17.py  pipeline_2020.02.29_06-33-25.pypipeline_2020.02.29_00-58-04.py  pipeline_2020.02.29_07-13-35.pypipeline_2020.02.29_02-00-52.py  pipeline_2020.02.29_08-45-23.pypipeline_2020.02.29_02-31-57.py  pipeline_2020.02.29_09-16-41.pypipeline_2020.02.29_03-02-51.py  pipeline_2020.02.29_11-13-00.pypipeline_2020.02.29_05-01-17.py當(dāng)前代碼:import google.datalab.storage as storagefrom pathlib import Pathbucket = storage.Bucket('machine_learning_data_bucket')for file in Path('').rglob('*.py'):    # API CODE GOES HERE當(dāng)前工作解決方案:!gsutil cp checkpoints/*.py gs://machine_learning_data_bucket
查看完整描述

1 回答

?
藍(lán)山帝景

TA貢獻(xiàn)1843條經(jīng)驗(yàn) 獲得超7個(gè)贊

這是為我工作的代碼:


from google.cloud import storage

from pathlib import Path


storage_client = storage.Client()

bucket = storage_client.bucket('bucket')


for file in Path('/home/jupyter/folder').rglob('*.py'):

    blob = bucket.blob(file.name)

    blob.upload_from_filename(str(file))

    print("File {} uploaded to {}.".format(file.name,bucket.name))


輸出:


File file1.py uploaded to bucket.

File file2.py uploaded to bucket.

File file3.py uploaded to bucket.

編輯

或者,您可以使用:


import google.datalab.storage as storage

from pathlib import Path


bucket = storage.Bucket('bucket')


for file in Path('/home/jupyter/folder').rglob('*.py'):

    blob = bucket.object(file.name)

    blob.write_stream(file.read_text(), 'text/plain')

    print("File {} uploaded to {}.".format(file.name,bucket.name))

輸出:


File file1.py uploaded to bucket.

File file2.py uploaded to bucket.

File file3.py uploaded to bucket.


查看完整回答
反對(duì) 回復(fù) 2022-08-16
  • 1 回答
  • 0 關(guān)注
  • 122 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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