使用ID读取文件
如果此文件的编辑权向所有得知链接的人公开,不论此文件是否存在于自己的Gdrive,都可以将它下载到colab读取
!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.
auth.authenticate_user()
gauth = GoogleAuth()
gauth.credentials = GoogleCredentials.get_application_default()
drive = GoogleDrive(gauth)
id = '1r3-------EcM1' #Gdrive链接
downloaded = drive.CreateFile({'id':id})
downloaded.GetContentFile('AAPL.csv')
#下载到Colab本地
import pandas as pd
df = pd.read_csv('AAPL.csv') #读取
在Colab调用.py文件的代码
将文件拉到Gdrive ----> 进入文件所在Gdrive目录 -----> import目标代码
from google.colab import drive
drive.mount("/content/drive")
import os
path="/content/drive/My Drive/Colab Notebooks"
os.chdir(path)
os.listdir(path)
from signalHandler import signalHandler