[Python-Dev] Relative import

Nick Coghlan ncoghlan at iinet.net.au
Wed Dec 17 07:58:20 EST 2003

Greg Ewing wrote:

> So I think we really want *three* kinds of module reference:
>    A: Explicitly absolute
>    B: Explicitly relative to the current module
>    C: Searched for upwards in the package hierarchy from the current
>       module
> (Note that C is a generalisation of the current "ambiguous"
> references which only look in two places.)

Alternate spellings (plus category D, which is "Python 2.3 semantics"):

A: from __absolute__.dotted.name import foo
B: from __relative__.dotted.name import bar
C: from __heirarchy__.dotted.name import foobar
D: from dotted.name import barfoo

I believe this spelling would only require import to handle the special 
cases as the first 'package' name (although having the compiler 
recognise them may be a later optimisation), and should also work with 
straight "import __absolute__.dotted.name.foo" statements.

Then Guido's migration plan would apply to the progression of the D 
semantics from the Python 2.3 model to being a shorthand for the 
absolute semantics.

And once _that_ has happened, then we could get rid of the 
'__absolute__' version in the name of TOOWTDI.


Nick Coghlan               |     Brisbane, Australia
Email: ncoghlan at email.com  | Mobile: +61 409 573 268

More information about the Python-Dev mailing list