Created
June 28, 2018 09:19
-
-
Save NISH1001/908458d21f1ccf5edaf447b08d281e80 to your computer and use it in GitHub Desktop.
Downlaod/Upload files from/to google drive in google colab
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Install the PyDrive wrapper & import libraries. | |
# This only needs to be done once in a notebook. | |
!pip install -U -q PyDrive | |
from pydrive.auth import GoogleAuth | |
from pydrive.drive import GoogleDrive | |
from google.colab import auth | |
from oauth2client.client import GoogleCredentials | |
# Authenticate and create the PyDrive client. | |
# This only needs to be done once in a notebook. | |
auth.authenticate_user() | |
gauth = GoogleAuth() | |
gauth.credentials = GoogleCredentials.get_application_default() | |
drive = GoogleDrive(gauth) | |
# Create & upload a file. | |
uploaded = drive.CreateFile({'title': 'filename.csv'}) | |
uploaded.SetContentFile('filename.csv') | |
uploaded.Upload() | |
print('Uploaded file with ID {}'.format(uploaded.get('id'))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment