iPython %run and %autoreload
It is a common scenario to use iPython to execute a python module (file) much like we would run `python module_name.py` in our command line.
We can do the same using the `%run` command in our iPython shell (like this `%run module_name.py`) and this gives us the best of both worlds – persist code in a text file (a .py file/”module”) while running it to experiment interactively with the outcome of the code in iPython environment. However, in our iPython shell, complications begin when the target module that we are running imports a second module. Even with `%autoreload` set to 2, the 2nd module will not reload correctly as expected.
Here’s a stackoverflow question dated 31st Oct (2012) - http://stackoverflow.com/questions/13150259/ipython-re-importing-modules-when-using-run/ - with an explicit example.
The trick, at this time of writing, appears to be using the `dereload()` ipython function to force a deep reload, with an issue on ipython project’s source proposing to improve `%run` to do a deep reload in the future.