How to access files in Google Drive from Google Colab?
To read or write files located in Google Drive from Google Colab Python scripts , the best option is to use the dedicated package from Google:
from google.colab import drive
drive.mount('/content/drive')
Once you run the above lines, Google Drive will ask for authorization. After granting access to the directory, the mounting point of the google drive should be printed in the console:
Mounted at /content/drive
To access files located in Google Drive, the path should start with /content/drive/My Drive/
as on the following example:
# Load the text file located in my_path
f = open('/content/drive/My Drive/my_path/file.txt')
# Print the text file content
print (f.read())
To read or write files located in Google Drive from Google Colab Python scripts , the best option is to use the dedicated package from Google:
from google.colab import drive
drive.mount('/content/drive')
Once you run the above lines, Google Drive will ask for authorization. After granting access to the directory, the mounting point of the google drive should be printed in the console:
Mounted at /content/drive
To access files located in Google Drive, the path should start with /content/drive/My Drive/
as on the following example:
# Load the text file located in my_path
f = open('/content/drive/My Drive/my_path/file.txt')
# Print the text file content
print (f.read())
To read or write files located in Google Drive from Python scripts run in Google Colab, the best option is to use the dedicated package:
from google.colab import drive
drive.mount('/content/drive')
Once you run the above lines, Google Drive will ask for authorization. After granting access to the directory, the mounting point of the google drive should be printed in the console:
Mounted at /content/drive
To access files located in Google Drive, the path should start with /content/drive/My Drive/
as on the following example:
# Load the text file located in my_path
f = open('/content/drive/My Drive/my_path/file.txt')
# Print the text file content
print (f.read())
# | ID | Query | URL | Count |
---|