[Python-Dev] Peculiar import code in pickle.py (original) (raw)
Alexander Belopolsky alexander.belopolsky at gmail.com
Tue Jul 13 17:25:23 CEST 2010
- Previous message: [Python-Dev] Problem with executing python interpretetor on special build of win server 2003
- Next message: [Python-Dev] Peculiar import code in pickle.py
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
When pickle.py needs to import a module by name, it goes through a peculiar dance of
__import__(module, level=0)
mod = sys.modules[module]
As far as I can tell, unless builtins.import is overridden or sys.modules clobbered by user code, the above should be equivalent to
mod = __import__(module, level=0)
Note that the optimized _pickle implementation does not do the sys.modules lookup and simply uses the module returned by import(..). This code goes back to 1999, so there was probably a good reason back then to write it this way. Presently, however, it seems to be just another obscure difference between C and Python implementation of pickle.
- Previous message: [Python-Dev] Problem with executing python interpretetor on special build of win server 2003
- Next message: [Python-Dev] Peculiar import code in pickle.py
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]