简体   繁体   English

在Google colaboratory中打开上传的文件

[英]Opening uploaded file in google colaboratory

When I upload and try to open the file using the below code, I am getting this error: 当我上传并尝试使用以下代码打开文件时,出现此错误:

IOError: [Errno 2] No such file or directory IOError:[Errno 2]没有这样的文件或目录

My code is as follows: 我的代码如下:

from google.colab import files

#upload file
uploaded = files.upload() 

# Open file
f = open(uploaded['small.txt'], 'r')

# Feed the file text into findall(); it returns a list of all the found strings
strings = re.findall(r'ne\w', f.read())

The problem is this line: 问题是这一行:

f = open(uploaded['small.txt'], 'r')

When you upload a file using uploaded = files.upload() , the actual file contents are stored in uploaded['small.txt'] , not the path. 当您使用上uploaded = files.upload()上载文件时,实际文件内容存储在上uploaded['small.txt'] ,而不是路径中。

So, I believe it should fix the error to simply use uploaded['small.txt'] directly in the regexp, eg, 因此,我认为它应该解决该错误,以便直接在正则表达式中直接使用uploaded['small.txt'] ,例如,

strings = re.findall(r'ne\w', uploaded['small.txt'])

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

相关问题 使用google-colaboratory上传到google驱动器的文件的路径是什么? - What is the path of the file uploaded to google drive using google-colaboratory? 如何使用 Colaboratory 复制 google 文件? - How to copy a google file with Colaboratory? 打开上传的csv文件 - Opening an uploaded csv file 无论如何我可以在Google colaboratory下载该文件吗? - Is there anyway I can download the file in Google colaboratory? 无法从 google-colaboratory 打开 google-storage 中的文件 - Unable to open file in google-storage from google-colaboratory 如何将 csv 文件(并使用它)从谷歌驱动器上传到谷歌合作实验室 - How to upload csv file (and use it) from google drive into google colaboratory 导入存储在google drive中的google colaboratory中的zip文件 - importing zip file in google Colaboratory stored in google drive 如何访问Google合作实验室根目录中的csv文件? - How to access csv file in the root folder of the Google Colaboratory? 如何在Google Colaboratory中导入和读取shelve或Numpy文件? - How to import and read a shelve or Numpy file in Google Colaboratory? 在Google colaboratory中使用带有OpenCV的文件路径加载文件 - Loading files using file paths with opencv in google colaboratory
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM