[Python-Dev] Relative import (original) (raw)
Skip Montanaro skip at pobox.com
Thu Dec 18 09:49:39 EST 2003
- Previous message: [Python-Dev] Relative import
- Next message: [Python-Dev] Re: Relative import
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
>> It has been proposed (more than once I think) that such a stdlib
>> package could be created in parallel using symlinks....
Michael> Are you sure that you won't get multiple copies of the same
Michael> module floating around? E.g. will you have
Michael> from httplib import HTTPConnection as HC1
Michael> from std.httplib import HTTPConnection as HC2
Michael> HC1 is HC2
Michael> I think in the scheme sketched above this will be false, which
Michael> kills the idea stone dead.
Maybe the symlink idea won't work. It seems that it would work to import the standard modules from std/init.py though. I performed a simple experiment. I created the std directory, added a symlink in it for the random module and added an init.py file with this content:
import sys
import urlparse
Here's the result:
>>> import random
>>> from std import random as random2
>>> random is random2
False
>>> import urlparse
>>> from std import urlparse as urlparse2
>>> urlparse is urlparse2
True
>>> import sys
>>> from std import sys as sys2
>>> sys is sys2
True
If we added a significant number of modules to std/init.py, startup would slow to a crawl. I imagine some sort of delayed import mechanism could be crafted to avoid this problem though.
Skip
- Previous message: [Python-Dev] Relative import
- Next message: [Python-Dev] Re: Relative import
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]