'Is there any prebuilt function in the google.colab module or in the PyDrive library to find a file's location on Google Drive?

I'm working on a Data Science project with a teammate. As we are working on the same notebooks on different machines, I thought it would be a good idea to use Google Colab.

Unfortunately, nevertheless, saving a Google Colab notebook doesn't save the data, forcing us to upload it every time. One way I came up with to solve this issue is to save all notebooks along with the data in a folder shared between us.

The problem now is that we are working on the same code. Both our notebooks need to access the same data, but after mounting the drive:

from google.colab import drive
drive.mount('/content/drive')

the data appears in different locations for both of us. For the owner of the folder, it appears as:

v drive
    v MyDrive
        > Colab Notebooks

Whereas for the editor it appears in a different location:

v drive
    v Shareddrives
        > Colab Notebooks

We need to write the same lines of code to access the file, otherwise only one of us will be able to reliably open them without editing the code every time.

One simple way to get around the problem would be to write a line of code which, given the notebook name, looks for the notebook file on Google Drive and outputs its location. Something akin to:

file_location = find_function('notebook_filename.ipynb')
%cd file_location
%ls
'dataset1.txt' 'dataset2.txt' ... 'notebook_filename.ipynb'
dataset = np.loadcsv('dataset1.txt')

Is there any prebuilt function in the google.colab module or in the PyDrive library to find a file's location on Google Drive? The same way it's done using the "Search Drive" tab?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source