简体   繁体   English

在 Google Colab 和 Python 脚本中使用文件

[英]Using Files in Google Colab & Python Script

I'm using Google Colab with a Python script that filters out poor data for Machine Translation.我正在使用带有 Python 脚本的 Google Colab,该脚本可以过滤掉机器翻译的不良数据。 I get it to ask the user the name of the files and set the path to those files.我得到它来询问用户文件的名称并设置这些文件的路径。

#Let User define path
path = "/drive/My\ Drive/CorpFilterr"

#Let User define files
source = path+input("Source input:")
target = path+input("Target input:")
new_src = path+input("Source destination:")
new_tgt = path+input("Target destination:")

Right now, I'm not sure my path variable is correct, I mean if I was to navigate my files in Colab in that order by hand, I'd find my files, but if it is formatted correctly for Colab.现在,我不确定我的path变量是否正确,我的意思是,如果我要在 Colab 中按该顺序手动导航我的文件,我会找到我的文件,但如果它为 Colab 正确格式化。

Upon running my script and entering all my file names I get a standard FileNotFoundError :运行我的脚本并输入我所有的文件名后,我得到一个标准FileNotFoundError

Traceback (most recent call last):
  File "Filter.py", line 112, in <module>
    with open(source, "r+") as f:
FileNotFoundError: [Errno 2] No such file or directory: '/drive/My Drive/CorpFilterr/EUbookshop.en-ga.en'

I tried changing the path to /drive/My\ Drive/CorpFilterr/ , but threw the same error.我尝试将path更改为/drive/My\ Drive/CorpFilterr/ ,但抛出了同样的错误。 I'm not sure how to handle files and scripts like this in Colab.我不确定如何在 Colab 中处理这样的文件和脚本。

Any help would be appreciated, Justin任何帮助将不胜感激,贾斯汀

I believe that you can't access your google drive from a google colab instance without code to do so if I run the command !ls I get one folder named sample_data and nothing else我相信如果我运行命令!ls我得到一个名为 sample_data 的文件夹,没有其他代码,你无法从没有代码的谷歌 colab 实例访问你的谷歌驱动器

So you should probably write some code to do that or upload the files manually因此,您可能应该编写一些代码来执行此操作或手动上传文件

EDIT 1: Just found out there is a button to mount Google Drive but that mounts it to /content/drive and not just /drive编辑 1:刚刚发现有一个按钮可以挂载 Google Drive,但它会将其挂载到/content/drive而不仅仅是/drive

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM