【发布时间】:2019-05-06 05:57:52
【问题描述】:
我已阅读有关如何打开驱动器的notebook。我已经按照指示使用:
from google.colab import drive
drive.mount('/content/drive')
之后,我可以使用!ls 列出我的驱动器的内容,但我无法读取或打开任何文件。我已经试过了:
with open("/content/drive/My Drive/filename.ext", "r") as file:
file = open("/content/drive/My Drive/filename.ext", "r")
!cp "/content/drive/My Drive/filename.ext" "filename.ext"
还有
import pandas as pd
file = pd.read_csv("/content/drive/My Drive/filename.ext")
但以上都没有奏效。我总是得到“不支持操作”或“无法打开文件进行阅读”。 我看到了一些使用 PyDrive 的建议。但这是通过将文件从 Google Drive 复制到 Google Drive 来完成的。我不明白为什么你必须来回复制文件,因为我需要遍历文件夹中的所有文件。 为什么 google colab 不能只读取存储在驱动器上的文件?还是我做错了什么?另一件事是我上传了一堆 csv 文件,但谷歌驱动器将它们列为“.csv.gsheet”(使用 glob)。这可能是问题吗?我没有其他想法。
【问题讨论】:
标签: google-drive-api google-colaboratory