Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

read file from google drive colab

from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
from google.colab import auth
from oauth2client.client import GoogleCredentials
Comment

read file from google drive colab

downloaded = drive.CreateFile({'id':"your_file_ID"})   # replace the id with id of file you want to access
downloaded.GetContentFile('your_file_name.csv')        # replace the file name with your file
Comment

read file from drive in colab

!pip install -U -q PyDrive
import os
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
from google.colab import auth
from oauth2client.client import GoogleCredentials

# 1. Authenticate and create the PyDrive client.
auth.authenticate_user()
gauth = GoogleAuth()
gauth.credentials = GoogleCredentials.get_application_default()
drive = GoogleDrive(gauth)

# choose a local (colab) directory to store the data.
local_download_path = os.path.expanduser('~/data')
try:
  os.makedirs(local_download_path)
except: pass

# 2. Auto-iterate using the query syntax
#    https://developers.google.com/drive/v2/web/search-parameters
file_list = drive.ListFile(
    {'q': "'1SooKSw8M4ACbznKjnNrYvJ5wxuqJ-YCk' in parents"}).GetList()

for f in file_list:
  # 3. Create & download by id.
  print('title: %s, id: %s' % (f['title'], f['id']))
  fname = os.path.join(local_download_path, f['title'])
  print('downloading to {}'.format(fname))
  f_ = drive.CreateFile({'id': f['id']})
  f_.GetContentFile(fname)


with open(fname, 'r') as f:
  print(f.read())
Comment

read file from google drive colab

auth.authenticate_user()
gauth = GoogleAuth()
gauth.credentials = GoogleCredentials.get_application_default()
drive = GoogleDrive(gauth)
Comment

PREVIOUS NEXT
Code Example
Python :: iterrows pd 
Python :: flask blueprints 
Python :: python sys environment 
Python :: Python NumPy stack Function Example with 1d array 
Python :: numpy primes 
Python :: check command 
Python :: design patterns python 
Python :: import tkinter module in python file 
Python :: python code for binary search tree 
Python :: convert to lwercase in df column 
Python :: python combine nested for loops 
Python :: get all commands discord.py 
Python :: how to set propee timeline in python 
Python :: how to split strings in python 
Python :: python dictionary map function 
Python :: xlrd python read excel 
Python :: puthon for loop 
Python :: label_map dict = label_map_util.get_label_map_dict(label_map) 
Python :: seaborn documentation x axis range 
Python :: closure python 
Python :: fixed size list in python 
Python :: selenium webdriver without opening browser 
Python :: iterating a list in python 
Python :: python find oldest and newest date 
Python :: python How do you find the middle element of a singly linked list in one pass? 
Python :: Uninstalling/removing a package is very easy with pip: 
Python :: what is indentation in python 
Python :: python count elements in sublists 
Python :: prolog finding the max from a list of facts 
Python :: remove last digit from number python 
ADD CONTENT
Topic
Content
Source link
Name
7+4 =