'reload M' doesn't update 'from M inport *'

Jean-Michel Pichavant jeanmichel at sequans.com
Fri Jul 9 13:38:18 EDT 2010


Frederic Rentsch wrote:
> I develop in an IDLE window.
>
> Module M says 'from service import *'.
> Next I correct a mistake in function 'service.f'.
> Now 'service.f' works fine.
>
> I do 'reload (service); reload (M)'.
> The function 'M.f' still misbehaves.
>
> 'print inspect.getsource (service.f)' and
> 'print inspect.getsource (M.f)' shows the same 
> corrected code. 
>
> 'print service.f' and 'print M.f' show different ids.
>
> So I do 'del M; reload (M)'. Nothing changes.
>
> I delete M again and run gc.collect () to really 
> clean house. I reload M again and still nothing changes.
> The id of the reloaded function 'M.f' is still the 
> same as it was before the purge and so M.f still isn't 
> fixed.  
>
> I know I have more radical options, such as starting 
> a new IDLE window. That would save me time, but 
> I'd like to take the opportunity to understand what
> is happening. Surely someone out there knows.
>
> Frederic
>  
>
>
>
>
>   
Hi,

Don't use reload, this is nothing but a trap, espacially if your using 
it to update your objects with the code you are writting.

JM

PS : You're misusing the del statement. It does not remove any object 
from mmory, however, it removes the reference to it, the object is still 
in memory. They are very few cases where del is usefull in python, so 
try to avoid using it as well.



More information about the Python-list mailing list