Search code examples
pythongoogle-colaboratoryfile-read

Getting FileNotFound error on Google Colab


I am trying to get data from a file using:

fileName = 'file_xyz'
f = open(fileName,'r')

on Google Colab.

However I keep getting file not found error.

FileNotFoundError: [Errno 2] No such file or directory: 'file_xyz'

I made sure the code and the file are on the same directory. I do not know how to solve this.


Solution

  • By default, Colab sets the working directory to /content. You can move your file there and use your code or, alternatively, open the file via its absolute path.