Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I reload a class definition in ipython

Tags:

ipython

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!

like image 997
Wen Avatar asked Aug 23 '12 05:08

Wen


1 Answers

Yes, there's an IPython extension called 'autoreload' for exactly this sort of thing. Here's the documentation on how to use it.

like image 176
Thomas K Avatar answered Nov 15 '22 00:11

Thomas K