【问题标题】:How to Load a Text File Correctly in Google Colab如何在 Google Colab 中正确加载文本文件
【发布时间】:2020-09-27 13:55:29
【问题描述】:

我在 Google Colab 中上传文本文件时遇到问题。

这里是代码

def load_doc(filename):
    # Opening the file as read only
    file = open(filename, 'r')
    text = file.read()
    file.close()
filename = (r'C:\Semicolon\ImageCaptionGenerator\Flickr8k_text\Flickr8k.token.txt')
doc = load_doc(filename)

保存到变量文件名中的文件路径是直接从我的系统中提取的。因此,我确信这没有问题,并且文件夹中存在 Flickr8k.token.txt。

这是不断弹出的错误。我尝试使用不同的方法读取不同的文本文件,但一直收到此错误。

FileNotFoundError                         Traceback (most recent call last)
<ipython-input-26-0d5546a08ca7> in <module>()
      5     file.close()
      6 filename = (r'C:\Semicolon\ImageCaptionGenerator\Flickr8k_text\Flickr8k.token.txt')
----> 7 doc = load_doc(filename)

<ipython-input-26-0d5546a08ca7> in load_doc(filename)
      1 def load_doc(filename):
      2     # Opening the file as read only
----> 3     file = open(filename, 'r')
      4     text = file.read()
      5     file.close()

FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Semicolon\\ImageCaptionGenerator\\Flickr8k_text\\Flickr8k.token.txt'

我能做些什么来完成这项工作。这是我第一次在 Google Colab 中上传文本文件。请帮忙

【问题讨论】:

    标签: python machine-learning data-science google-colaboratory


    【解决方案1】:

    使用笔记本左侧文件浏览器中的文件上传按钮。

    这是一个突出显示相关按钮的屏幕截图。

    【讨论】:

    • 我实际上使用的是 Google Colab Tensorflow GPU,猜想界面是完全不同的。在文件中,我只能看到上传笔记本等
    猜你喜欢
    • 2022-11-07
    • 2020-02-05
    • 2020-06-07
    • 2021-06-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-14
    • 1970-01-01
    相关资源
    最近更新 更多