since I usually use ipython to play around with code under development, I come across the situation where I change the code of a class after I import it to ipython. I want to reload the new class definition without restarting ipython. The problem is that the reload function in ipython only works with modules.
I searched the solution to this problem and found a previous thread: how to reload a Class in python shell?
However, I followed the approaches there but it didn't work. I think the reason why it works in that thread is that the class name happened to be the same with the module name, so it can be found in sys.modules and thus can be deleted. When the class name is different from the module name, that approach cannot work.
I am wondering if there is solution to this problem. Thanks!
Yes, there's an IPython extension called 'autoreload' for exactly this sort of thing. Here's the documentation on how to use it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With