[Python-Dev] Relative vs. absolute imports (original) (raw)

Phillip J. Eby pje at telecommunity.com
Mon May 17 11:50:22 EDT 2004


At 05:37 PM 5/17/04 +0200, M.-A. Lemburg wrote:

Samuele Pedroni wrote:

At 16:55 17.05.2004 +0200, M.-A. Lemburg wrote:

Are you saying that you are not going to change the default import() implementation, only the way it is called ? (I wonder how you'll enforce the 'absolute only' strategy then) if you pass globals = {} you get absolute imports from import, Ahh, a hidden feature :-) I didn't know that one yet.

More of an emergent property. Keep in mind that the current relative mechanism is always relative to something, and that "something" is defined by the globals['name'], if any. If there is no 'name', then the import has to be absolute. For example, you would expect this:

 exec "import foo" in {},{}

to be an absolute import, would you not?



More information about the Python-Dev mailing list