I use IPython to interactively use and debug code that I edit in a text editor at the same time. Unfortunately, Python does not automatically reload packages and functions after an initial
import foo, simply for performance reasons.
Fortunately, there is a solution: the IPython extension autoreload does what its name says: either all (how I use it) or only selected (imported using magic function
%aimport) are refreshed, whenever I hit the Enter key. Here’s a short how-i-use-it demo, involving a minimal package
foo with a helloworld function
In : %load_ext autoreload In : %autoreload 2 In : import foo In : foo.bar() Hello World! In : !cat foo.py def bar(): print('Hello World!\n') In : # edit foo.py in editor In : !cat foo.py def bar(): print('Hello me!\n') In : # bar() is automagically reloaded In : foo.bar() Hello me!
How do you get it? It’s already bundled with IPython by default! Happy hacking!