Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reload module from a folder?

Since IPython Notebook does not reload the file after I modified my module, I am trying to reload it. There was a post on how to do similar things, but my problem is when the .py file is in a subfolder, it does not work.

My original import works like this:

from myutils.MyClassFile import MyClass

while trying to reload:

reload(myutils.MyClassFile)
from myutils.MyClassFile import MyClass

I got the error:

name 'myutils' is not defined

Any suggestion on how to achive this.

like image 662
Bin Avatar asked Apr 01 '26 14:04

Bin


1 Answers

In the notebook:

%load_ext autoreload
%autoreload 2

enables auto reload of all imported modules that changed for each execution of a cell.

You can exclude modules with:

%aimport module_to_exclude

Alternatively use:

%autoreload 1

and whitelist what should be reloaded:

%aimport module_to_include
like image 162
Mike Müller Avatar answered Apr 04 '26 02:04

Mike Müller



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!