【问题标题】:How can I get the Google Drive ID of the current Google Colab notebook programmatically?如何以编程方式获取当前 Google Colab 笔记本的 Google Drive ID?
【发布时间】:2020-05-05 15:14:29
【问题描述】:

我正在使用 Google Colab 笔记本。我想获得这个笔记本的 Google Drive 详细信息——比如 Python __file__ 等价物——所以我可以获得它的文件夹。

有没有一种方法可以以编程方式获取当前笔记本的 Google Drive ID(和其他元数据),以便获取其父级?

【问题讨论】:

    标签: google-drive-api google-colaboratory


    【解决方案1】:

    您好,我正在使用drive 与驱动器进行低级交互,您可以轻松地将其安装在 colab 中:

    !wget https://dl.google.com/go/go1.14.2.linux-amd64.tar.gz
    !tar -C /usr/local -xzf go1.14.2.linux-amd64.tar.gz
    import os
    os.environ['PATH'] += ":/usr/local/go/bin"
    !go get -u github.com/odeke-em/drive/cmd/drive
    os.environ['PATH'] += ":/root/go/bin"
    

    而且你可以操纵你的驱动器:

    !drive init
    !drive index -no-prompt -quiet
    !drive pull -directories -depth 4 -quiet -no-prompt -fix-clashes
    

    它适用于文件 id 和名称,并使用驱动器覆盖大多数用例。

    打印有问题,所以在大多数命令中添加选项-quiet -no-prompt

    【讨论】:

      猜你喜欢
      • 2019-12-17
      • 2022-09-27
      • 1970-01-01
      • 2018-09-14
      • 2023-02-22
      • 1970-01-01
      • 2020-10-01
      • 1970-01-01
      相关资源
      最近更新 更多