## 上傳
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