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

Frederic Rentsch anthra.norell at bluewin.ch
Fri Jul 9 17:14:23 EDT 2010


On Fri, 2010-07-09 at 19:38 +0200, Jean-Michel Pichavant wrote:
> 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

I've found "reload" very usable for development in IDLE. IDLE memorizes
my input, and the variables I assign output to. If restart IDLE I lose
it all and start over. That is an awfully awkward alternative to
"reload", an alternative I wouldn't consider.
   I found "reload" tricky with several modules, because all
dependencies need to be updated and which way they go isn't always
obvious. Reloading all modules in the right order works for me. The
reload commands come up with Alt-P as long, precisely, as I don't
restart IDLE. 

 S : 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.

I understand that things going out of scope delete themselves. I have
used del on occasion, for instance, to get rid of invalid members of a
list or a dictionary. It has to be done in two passes, though, because
neither can be altered during an iteration. The first pass makes a
delete list of indices or keys, so that the actual deletion iterates
through the delete list, not the object deleted from. 
   Would you call that a misuse?

Frederic





More information about the Python-list mailing list