Sab*_*deH 7 python file google-colaboratory
当我在 google colab 中编写这段代码时:
import pickle
x=10;
output = open('data.pkl', 'wb')
pickle.dump(x,output)
Run Code Online (Sandbox Code Playgroud)
x 已保存,并且还在 Google Colab 的另一个窗口中,我可以访问该文件并阅读它,但我不知道该文件在哪里。有人知道它在哪里吗?
它在当前目录中。您也可以使用以下命令将其下载回本地计算机
from google.colab import files
files.download(‘data.pkl’)
Run Code Online (Sandbox Code Playgroud)
小智 5
您可以将其上传到您的 Google 驱动器:
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
from google.colab import auth
from oauth2client.client import GoogleCredentials
# 1. Authenticate and create the PyDrive client.
auth.authenticate_user()
gauth = GoogleAuth()
gauth.credentials = GoogleCredentials.get_application_default()
drive = GoogleDrive(gauth)
# get the folder id where you want to save your file
file = drive.CreateFile({'parents':[{u'id': folder_id}]})
file.SetContentFile('data.pkl')
file.Upload()
Run Code Online (Sandbox Code Playgroud)
此代码基本上从云 VM 中获取 data.pkl 并将其永久上传到特定文件夹下的 Google Drive。
如果您选择不指定文件夹,文件将上传到您的 Google Drive 的根目录下。