Prevent Python from caching the imported modules
Posted
by Olivier
on Stack Overflow
See other posts from Stack Overflow
or by Olivier
Published on 2010-05-27T06:16:17Z
Indexed on
2010/05/27
6:21 UTC
Read the original article
Hit count: 1038
While developing a largeish project (split in several files and folders) in Python with IPython, I run into the trouble of cached imported modules.
The problem is that instructions import module
only reads the module once, even if that module has changed! So each time I change something in my package, I have to quit and restart IPython. Painful.
Is there any way to properly force reloading some modules? Or, better, to somehow prevent Python from caching them?
I tried several approaches, but none works. In particular I run into really, really weird bugs, like some modules or variables mysteriously becoming equal to None
...
The only sensible resource I found is Reloading Python modules, from pyunit, but I have not checked it. I would like something like that.
A good alternative would be for IPython to restart, or restart the Python interpreter somehow.
So, if you develop in Python, what solution have you found to this problem?
© Stack Overflow or respective owner