ojo
ojo

Reputation: 81

How to Load a Text File Correctly in Google Colab

I have issues uploading a text file in Google Colab.

Here is the code

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)

The file path saved into variable filename was lifted directly from my system. Thus, I am sure there's no issues with that and Flickr8k.token.txt exists in the folder.

This is the error that keeps popping up. I have tried reading different text files using different methods, I keep getting this error.

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'

What can i do to make this work. This is my first time uploading a text file in Google Colab. Kindly help

Upvotes: 0

Views: 7457

Answers (1)

Bob Smith
Bob Smith

Reputation: 38589

Use the file upload button in the file browser on the left hand side of the notebook.

Here's a screenshot with the relevant buttons highlighted.

enter image description here

Upvotes: 1

Related Questions