Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Colab: Reload imported modules

I have a file readfunctions.py inside a folder called functions (in this folder there is also a "init.py" file). In the file readfunctions.py I have defined a function called "read_from_shower".

./functions
    readfunctions.py
    __init__.py

So, I have imported this in my Google Colab Session (from GitHub after I cloned the repository):

from functions.readfunctions import read_from_shower

And it works fine. But then, I have made some changes in my function "read_from_shower" but I can reload it in Colab.

How can I do it?

like image 432
Laura Avatar asked May 14 '18 21:05

Laura


People also ask

How do I reload an imported module in Python?

The reload() method is used to reload a module. The argument passed to the reload() must be a module object which is successfully imported before.

How do I load data on Google Colab?

Click on “Choose Files” then select and upload the file. Wait for the file to be 100% uploaded. You should see the name of the file once Colab has uploaded it. Finally, type in the following code to import it into a dataframe (make sure the filename matches the name of the uploaded file).

How do I load multiple files in Colab?

You need to click on Mount Drive Option to the pane on the left side of the notebook and you'll get access to all the files stored in your drive. For importing multiple files in one go, you may need to write a function. Save this answer.


2 Answers

You can restart the runtime (which is annoying), or use something like

import importlib
importlib.reload(functions.readfunctions)
like image 160
sk29910 Avatar answered Oct 16 '22 05:10

sk29910


Just put this someplace

%load_ext autoreload
%autoreload 2
like image 37
Daniel Severo Avatar answered Oct 16 '22 06:10

Daniel Severo