I would like to be able to open the Python shell, execute some code defined in the module, then modify the module and then re-run it in the same shell without closing / reopening.
I tried to rename functions / objects after changing the script, and this does not work:
Python 2.7.2 (default, Jun 20 2012, 16:23:33) [GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> from my_module import buggy_function, test_input >>> buggy_function(test_input) wrong_value
It is clear that re-import did not give me a “new version” of the function.
In this case, it is not a matter of closing the interpreter and reopening it. But if the code I'm testing is complex enough, sometimes I have to make quite a few importing objects and define dummy variables to create a context that can adequately test the code. It is annoying to have to do this every time I make a change.
Does anyone know how to “update” module code inside a Python interpreter?
source share