Colabotray 加载drive中的数据

!apt-get install -y -qq software-properties-common python-software-properties module-init-tools
!add-apt-repository -y ppa:alessandro-strada/ppa 2>&1 > /dev/null
!apt-get update -qq 2>&1 > /dev/null
!apt-get -y install -qq google-drive-ocamlfuse fuse
from google.colab import auth
auth.authenticate_user()
from oauth2client.client import GoogleCredentials
creds = GoogleCredentials.get_application_default()
import getpass
!google-drive-ocamlfuse -headless -id={creds.client_id} -secret={creds.client_secret} < /dev/null 2>&1 | grep URL
vcode = getpass.getpass()
!echo {vcode} | google-drive-ocamlfuse -headless -id={creds.client_id} -secret={creds.client_secret}

出现链接,点击,复制验证码。
会出现两次。

# 指定Google Drive云端硬盘的根目录,名为drive
!mkdir -p drive
!google-drive-ocamlfuse drive
# 指定当前的工作文件夹
import os
# 此处为google drive中的文件路径,drive为之前指定的工作根目录,要加上
os.chdir("drive") 
import  os
os.getcwd() #获取当前工作目录路径  # '/content/drive'

drive文件挂在当前目录下
在这里插入图片描述
解压文件

shell 版比python版相比,天上和地上

shell版
unzip -d /temp test.zip 解压到指定路径
解压到指定文件夹下时,速度比较慢。可以先将文件夹解压到当前目录,然后再移动到指定路径
解压文件方法

unzip test.zip
mv test/ /temp

python 版

path = '/content/drive/input/data_dog.zip'

import zipfile
f = zipfile.ZipFile(path,'r')
for file in f.namelist():
#   print(file)
  f.extract(file,"/content/drive/input")
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值