import local file to google colab

Danf picture Danf · Mar 22, 2018 · Viewed 39.7k times · Source

I don't understand how colab works with directories, I created a notebook, and colab put it in /Google Drive/Colab Notebooks.

Now I need to import a file (data.py) where I have a bunch of functions I need. Intuition tells me to put the file in that same directory and import it with:

import data

but apparently that's not the way...

I also tried adding the directory to the set of paths but I am specifying the directory incorrectly..

Can anyone help with this?

Thanks in advance!

Answer

korakot picture korakot · Mar 22, 2018

Colab notebooks are stored on Google Drive. But it is run on another virtual machine. So, you need to copy your data.py there too. Do this to upload data.py through Colab.

from google.colab import files
files.upload()
# choose the file on your computer to upload it then
import data