Google Colab - Executing External Python Files - Tutorialspoint
Google Colab - Executing External Python Files - Tutorialspoint
Suppose, you already have some Python code developed that is stored in your Google Drive. Now,
you will like to load this code in Colab for further modifications. In this chapter, we will see how to
load and run the code stored in your Google Drive.
Mounting Drive
Type a few letters like “m” in the search box to locate the mount command. Select Mount Drive
command from the list. The following code would be inserted in your Code cell.
https://www.tutorialspoint.com/google_colab/google_colab_executing_external_python_files.htm 1/5
11/20/2020 Google Colab - Executing External Python Files - Tutorialspoint
If you run this code, you will be asked to enter the authentication code. The corresponding screen
looks as shown below −
Open the above URL in your browser. You will be asked to login to your Google account. Now, you
will see the following screen −
https://www.tutorialspoint.com/google_colab/google_colab_executing_external_python_files.htm 2/5
11/20/2020 Google Colab - Executing External Python Files - Tutorialspoint
If you grant the permissions, you will receive your code as follows −
https://www.tutorialspoint.com/google_colab/google_colab_executing_external_python_files.htm 3/5
11/20/2020 Google Colab - Executing External Python Files - Tutorialspoint
Cut-n-paste this code in the Code cell and hit ENTER. After a while, the drive will be mounted as
seen in the screenshot below −
Now, you are ready to use the contents of your drive in Colab.
You can list the contents of the drive using the ls command as follows −
This command will list the contents of your Colab Notebooks folder. The sample output of my drive
contents are shown here −
Now, let us say that you want to run a Python file called hello.py stored in your Google Drive. Type
the following command in the Code cell −
print("Welcome to TutorialsPoint!")
https://www.tutorialspoint.com/google_colab/google_colab_executing_external_python_files.htm 4/5
11/20/2020 Google Colab - Executing External Python Files - Tutorialspoint
Welcome to TutorialsPoint!
Besides the text output, Colab also supports the graphical outputs. We will see this in the next
chapter.
https://www.tutorialspoint.com/google_colab/google_colab_executing_external_python_files.htm 5/5