Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google colaboratory 希望使用colaboratory。将驱动器文件封装到python的最简单方法是什么?_Google Colaboratory - Fatal编程技术网

Google colaboratory 希望使用colaboratory。将驱动器文件封装到python的最简单方法是什么?

Google colaboratory 希望使用colaboratory。将驱动器文件封装到python的最简单方法是什么?,google-colaboratory,Google Colaboratory,我正在寻找简化/封装,以便使用(sic)open(“my_file.txt”)的现有程序可以移植到colaboratory,而现有逻辑流的变化最小。很高兴在我现有的逻辑之前有一些剪切/粘贴逻辑 我从google()中了解到的心智模型是,我必须完成这些先决条件才能加载文件 上传到谷歌硬盘 下载到python(vm,可能在 /(tmp) 然后,我可以执行我现有的代码,而不进行任何更改 因此,我怀疑/建议对我(而不仅仅是我!)有效的是一个接口/功能,如下所示: 输入(来自本地计算机) 源文件目录

我正在寻找简化/封装,以便使用(sic)open(“my_file.txt”)的现有程序可以移植到colaboratory,而现有逻辑流的变化最小。很高兴在我现有的逻辑之前有一些剪切/粘贴逻辑

我从google()中了解到的心智模型是,我必须完成这些先决条件才能加载文件

  • 上传到谷歌硬盘
  • 下载到python(vm,可能在 /(tmp)
  • 然后,我可以执行我现有的代码,而不进行任何更改

    因此,我怀疑/建议对我(而不仅仅是我!)有效的是一个接口/功能,如下所示:

    • 输入(来自本地计算机)
      • 源文件目录
      • 源文件名
      • (当然,隐式地需要身份验证输入)
    • 输出
      • python\u vm\u file\u dir(我可以在程序中使用的dir;/tmp很好)
      • (隐式地,我希望使用相同的dest_文件名)
    有了这个代码片段,我可以轻松地将代码移动到colaboratory中

    有人已经创建了这个吗


    谢谢。

    我一直在回答类似的问题。就简单性而言,我发现在谷歌云存储中保存数据文件是最容易的。这在教程中有很好的解释-

    我发现最简单的方法是插入单元格,将数据复制到运行笔记本的虚拟机上

    !gsutil cp gs://{bucket_name}/to_upload.txt /tmp/gsutil_download.txt
    
    这样,我通常可以保留本地运行的“活动”代码块


    当我外出时,我会使用chromebook,所以我喜欢尽可能多地保存在云端。将一个“映射网络驱动器”(在windows speak中)设置到GCS存储桶非常容易——用于移动文件。在Linux上也很容易。在Windows上,我发现这个工具真的很方便——不是一个广告,我只是一个粉丝

    我一直在解决类似的问题。就简单性而言,我发现在谷歌云存储中保存数据文件是最容易的。这在教程中有很好的解释-

    我发现最简单的方法是插入单元格,将数据复制到运行笔记本的虚拟机上

    !gsutil cp gs://{bucket_name}/to_upload.txt /tmp/gsutil_download.txt
    
    这样,我通常可以保留本地运行的“活动”代码块

    当我外出时,我会使用chromebook,所以我喜欢尽可能多地保存在云端。将一个“映射网络驱动器”(在windows speak中)设置到GCS存储桶非常容易——用于移动文件。在Linux上也很容易。在Windows上,我发现这个工具真的很方便——不是一个广告,我只是一个粉丝

    上传到谷歌硬盘。 下面是一个直接访问它的代码片段

    !apt-get install -y -qq software-properties-common python-software-properties 
    module-init-tools
    !add-apt-repository -y ppa:alessandro-strada/ppa 2>&1 > /dev/null
    !apt-get update -qq 2>&1 > /dev/null
    !apt-get -y install -qq google-drive-ocamlfuse fuse
    from google.colab import auth
    auth.authenticate_user()
    from oauth2client.client import GoogleCredentials
    creds = GoogleCredentials.get_application_default()
    import getpass
    !google-drive-ocamlfuse -headless -id={creds.client_id} -secret= 
    {creds.client_secret} < /dev/null 2>&1 | grep URL
    vcode = getpass.getpass()
    !echo {vcode} | google-drive-ocamlfuse -headless -id={creds.client_id} -secret= 
    {creds.client_secret}
    
    您可以简单地以drive/Filename的形式访问google drive中的任何文件

    例如

    此外,您只需为一台笔记本电脑执行一次。之后,您还可以访问其他笔记本电脑中的数据。

    上传到Google Drive。 下面是一个直接访问它的代码片段

    !apt-get install -y -qq software-properties-common python-software-properties 
    module-init-tools
    !add-apt-repository -y ppa:alessandro-strada/ppa 2>&1 > /dev/null
    !apt-get update -qq 2>&1 > /dev/null
    !apt-get -y install -qq google-drive-ocamlfuse fuse
    from google.colab import auth
    auth.authenticate_user()
    from oauth2client.client import GoogleCredentials
    creds = GoogleCredentials.get_application_default()
    import getpass
    !google-drive-ocamlfuse -headless -id={creds.client_id} -secret= 
    {creds.client_secret} < /dev/null 2>&1 | grep URL
    vcode = getpass.getpass()
    !echo {vcode} | google-drive-ocamlfuse -headless -id={creds.client_id} -secret= 
    {creds.client_secret}
    
    您可以简单地以drive/Filename的形式访问google drive中的任何文件

    例如

    此外,您只需为一台笔记本电脑执行一次。之后,您还可以访问其他笔记本电脑中的数据