import reloading

Dave Angel davea at davea.name
Wed Sep 24 07:54:58 EDT 2014


Robin Becker <robin at reportlab.com> Wrote in message:
> I'm tryng to bring some outdated ihooks code into the modern world.
> 
> I notice that module loaders are supposed to re-use an existing module if it is 
> already in sys.modules.
> 

No, the loader is required to reuse the existing module. 


> Is a loader supposed to reset all the reused module's attributes and reset the 
> __dict__ or does it just run the code from the module in hte __dict__?
> 

Nothing gets reset or run. It simply reuses the existing module object.

There are ways to fool the loader, for example by having a module
 visible in more than one file system path. 
The most common of
 these bugs  is a module that tries to import the script that's
 started it all. Because that initial script is named __main__
 internally,  if you try to import it by filename you end up with
 two instances.


-- 
DaveA




More information about the Python-list mailing list