look further down sys.path for extension module

Alex Martelli aleaxit at yahoo.com
Thu Oct 28 04:35:40 EDT 2004


vincent wehren <vincent at visualtrans.de> wrote:
   ...
>  > Alternatively, you could rebuild zlib.pyd to be named pyzlib.pyd. You
> > need to rebuild the code because you also need to rename the entry
> > function, and the name of the module inside the module itself. You
> > can then do
> > 
> > import pyzlib as zlib
> 
> Yes, quickly tried that, too. It still is registered in sys.modules as
> "pyzlib" - don't known if I expected that...

The merely local renaming should not accidentally cause multiple
repetitions of the module's loading if somewhere else the module gets
simply imported with 'import pyzlib', of course.  So, it's recoded in
sys.modules['pyzlib'] -- anything else would be astonishing.

Just add a further statement
    sys.modules['zlib'] = zlib
right after this import, if you want future 'import zlib' statements to
get 'redirected' to use the already-imported pyzlib instead.


Alex



More information about the Python-list mailing list