【问题标题】:How to obtain the current path to my google colab file?如何获取我的 google colab 文件的当前路径?
【发布时间】:2022-11-06 21:00:05
【问题描述】:

我在我的谷歌驱动器上使用谷歌 colab。当我做

import os 
cwd= os.getcwd()
print (cwd)

它返回

/content

.如何获取我的 google colab 文件的路径,例如

/content/drive/path_to_my_current_google_colab_file

【问题讨论】:

    标签: google-colaboratory


    【解决方案1】:
    import os, glob
    
    my_name = 'my.ipynb'
    
    my_path = glob.glob(os.getcwd() + '/**/' +
    my_name, recursive = True)
    
    # some 'list comprehension'.
    my_path = [my_i
    for my_i in my_path if len(my_i) in [max([len(my_i)
    for my_i in my_path])]
    ][0]; print(my_path)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-02
      • 2023-03-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多