当我在google中编写这段代码时:
import pickle
x=10;
output = open('data.pkl', 'wb')
pickle.dump(x,output)X被保存,而且在Google的另一个窗口中,我可以访问这个文件并读取它,但是我不知道文件在哪里。有人知道它在哪吗?
发布于 2018-02-08 10:02:16
你可以上传到你的谷歌驱动器:
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() 这段代码基本上是从云VM中获取data.pkl,并将其永久上传到特定文件夹下的Google。
如果您选择不指定一个文件夹,该文件将上传到您的Google根目录下。
发布于 2018-02-01 20:25:17
它在当前目录中。您还可以将其下载回本地计算机
from google.colab import files
files.download(‘data.pkl’)发布于 2021-06-26 10:41:23
您可以在google驱动器文件夹中的任何位置保存和读取转储文件。
import gc
import pickle
from google.colab import drive
drive.mount('/content/drive', force_remount=True)
pick_insert = open('drive/My Drive/data.pickle','wb')
pickle.dump(data, pick_insert)
pick_insert.close()
pick_read = open('drive/My Drive/data.pickle','rb')
data = pickle.load(pick_read)
pick_read.close()https://stackoverflow.com/questions/48558007
复制相似问题