简体   繁体   中英

Using Files in Google Colab & Python Script

I'm using Google Colab with a Python script that filters out poor data for Machine Translation. 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.

Upon running my script and entering all my file names I get a standard 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. I'm not sure how to handle files and scripts like this in 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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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