The Nightman
The Nightman

Reputation: 5759

Reloading python function

I am using a jupyter lab notebook and trying to modify code, reload it within the jupyter notebook and use the modified code without reloading the kernel. I am using python 3.5.5 and am running code like this:

(in file test.py)

def myTest():
    print('hello')

(in jupyter)

from test import myTest
import importlib
importlib.reload(test)
myTest()

When I run the code in my jupyter lab notebook I get a NameError that name 'test' is not defined. From searching on stackoverflow the only references I find to this error is problems using older version of python. But the way I am using importlib.reload() seems to be correct.

Upvotes: 3

Views: 3016

Answers (1)

Daniel Lenz
Daniel Lenz

Reputation: 3857

Have you tried the built-in magic command autoreload?

At the beginning of your notebook, add:

%load_ext autoreload
%autoreload 2

Upvotes: 9

Related Questions