## 上传
from google.colab import files uploaded = files.upload() for fn in uploaded.keys(): print(\'User uploaded file "{name}" with length {length} bytes\'.format( name=fn, length=len(uploaded[fn])))
## 下载
from google.colab import files with open(\'example.txt\', \'w\') as f: f.write(\'some content\') files.download(\'example.txt\')
## 获取谷歌硬盘的文件
## 方法1 要输入授权码 整个谷歌硬盘整体挂载
from google.colab import drive drive.mount(\'/content/gdrive\')
## 方法2 下载并解压,压缩文件
从google drive 选择某个压缩文件并解压(这里file_id的获取需要右键点击上传文件,选择“获取共享链接”。将Google Drive的zip文件的共享链接复制后
截取"open?id="后面的一串地址字符 粘贴到下面第二个代码块file_id=\' xxxxxxxxxxx \'的X的部分)
!pip install PyDrive googledrivedownloader
from google_drive_downloader import GoogleDriveDownloader GoogleDriveDownloader.download_file_from_google_drive(file_id=\'1I4YGP8LsZMJ6nyv0y3ncklds94XTg19z\',dest_path="./tmp.zip",unzip=True)
!rm tmp.zip !ls
### 写入并存储文件
with open(\'/content/gdrive/My Drive/foo.txt\', \'w\') as f: f.write(\'Hello Google Drive!\') !cat /content/gdrive/My\ Drive/foo.txt
### 升级安装 TensorFlow
# To determine which version you\'re using: !pip show tensorflow # For the current version: !pip install --upgrade tensorflow # For a specific version: !pip install tensorflow==1.2 # For the latest nightly build: !pip install tf-nightly
### 导入colab默认中没有的库 `!pip install` or `!apt-get install`
!pip install -q xxx
!apt-get -qq install -y xxx