如何确定 Google colab 中的文件路径?

How to determine file path in Google colab?

我用这个安装了我的驱动器: from google.colab import drive drive.mount('/content/drive/')

我在文件夹中有一个文件,我想要路径我该如何确定路径? 假设包含该文件的文件夹在我的驱动器

中命名为 'x'

路径将为 /content/drive/My\ Drive/x/the_file

作为函数参数的路径将是 /content/drive/My Drive/x/the_file,所以在 我的驱动器

除了手动输入外,我找不到任何简单的方法来执行此操作。

对我来说,它看起来像这样

dat = ZipFile('/content/drive/My Drive/Code/Tutorial/Assign 2 - New/weblogs.zip', 'r')

注意:

  • 你必须尊重空间。
  • 您不需要转义空格 - 即“我的目录”应该只是 'My Dir',而不是 'My\ Dir'。

这个答案可能对任何人都有用,因为我遇到了这个问题并提出了这个问题。

我的文件 utils.py 位于 "MyDrive/NotebookDatasets/CMVRLG",我正在尝试导入它。

这就是我们导入它的方式。 要安装 google 驱动器:

import os
from google.colab import drive
drive.mount('/content/gdrive')
import sys
sys.path.append('drive/gdrive/MyDrive/NotebookDatasets/CMVRLG')

下面是我们如何导入

import gdrive.MyDrive.NotebookDatasets.CMVRLG.utils