Python on Google Colab

As much as I am more comfortable using jupyter notebook on my local, I find that working on Google Colab is much more sustainable esspecially when I am working in a team. However, there are some small intricacies when using Google colab that is not exactly the same as using Jupyter notebook.

Installing and Upgrading package

Even though most basic packages are pre-installed, there will be need to install other packages. Use ! in front of the line will tell Google Colab that it is not a python code but instead a command line script.

To install package

!pip install python-chess

To upgrade an existing installed package

!pip install upgrade python-chess

To read/upload file in the local storage

from google.colab import files
import io

uploaded = files.upload()

for fn in uploaded.keys():
  print('User uploaded file "{name}" with length {length} bytes'.format(
      name=fn, length=len(uploaded[fn])))
data_path = 'baby2014.txt'
with open(data_path, 'r') as f:
    content = f.readlines()

To mount Google Drive storage

from google.colab import drive
drive.mount('/content/drive')

!ls "/content/drive/My Drive"

I hope this help

Previous