RCu*_*123 5 python google-colaboratory
我可以使用以下代码手动将文件上传到 Google Colab。
1 import json
2 from google.colab import files
3 uploaded = files.upload()
Run Code Online (Sandbox Code Playgroud)
每次到达 时Line 3,我都必须手动单击Upload File,然后在本地选择该文件,然后代码才能继续运行。经过几次运行后,即使我取消了上传Line 3,它似乎也可以在不上传文件的情况下正常运行。
每次在 Google Colab 中运行代码时,如何自动上传相同的文件(存储在本地)?或者我应该将其存储在 Google 云端硬盘中并链接文件的 URL?如果是这样,我将如何在代码中做到这一点?
我遇到了类似的问题,我能够在 Google Colab 中上传/链接文件
'''store a file in google drive and create a shareable link, change "file/d" to "uc?export=download&" and remove /view?usp=sharing.
This will create a link that you can store in a variable example below'''
#link = 'https://drive.google.com/file/d/1n2ZS50c_WbHBK9gIco4gRAUSm9uWfo3Q/view?usp=sharing'
# replace 'file/d/' with 'uc?export=download&id=' and remove '/view?usp=sharing'
#link = 'https://drive.google.com/uc?export=download&id=1n2ZS50c_WbHBK9gIco4gRAUSm9uWfo3Q'
'''Direct file link can also be saved to variable as below '''
# User inputs
fileLink = "https://raw.githubusercontent.com/pavanghai/DataSets/master/games.csv"
fileType = "csv"
fileLink1 = 'https://drive.google.com/uc?export=download&id=1n2ZS50c_WbHBK9gIco4gRAUSm9uWfo3Q'
Run Code Online (Sandbox Code Playgroud)
或者您可以创建一个下载文件,如下所示
# Download a filelink as file in google root folder "/content/"
!wget https://raw.githubusercontent.com/pavanghai/DataSets/master/games.csv -q
Run Code Online (Sandbox Code Playgroud)
-q 是相当模式