[Python-Dev] Relative import (original) (raw)
Devin devin at whitebread.org
Tue Dec 23 13:45:18 EST 2003
- Previous message: [Python-Dev] Relative import
- Next message: [Python-Dev] Re: Relative import
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Tue, 23 Dec 2003, Ken Manheimer wrote:
> This flowed well in my head, and looks natural. However, the suggestion > about '.' or '..' referring to the parent looks ugly and unnatural. > > Let's say '.' was used to spell "parent module", and let's assume that > the module 'a.b.c.d' wants to import 'a.b.e'. The absolute import would > be spelled: > > import a.b.e > > ... and the relative import would be spelled: > > import .....e # .[parent].[parent].e > > Yuck! (no offense :)
Truly, yuck. But in my model, the leading '.' dot, itself, stands for the containing package, and '..' stands for the containing package's package, and so forth: import ..e # [parent-of-parent].e
I can't quite get used to the idea of '.' having two different meanings depending on how many '.'s are found next to each other in an import statement. I believe that the notation above is concise, but is not very intuitive ...
Even using the leading '.' syntax, it would be good to have a specific identifier for the containing package, realized in each module and respected as a special identifier by the package machinery. I like 'pkg':
import pkg.sibling # == 'import .sibling' and import pkg.pkg.uncle # == 'import ..uncle' import pkg.pkg.uncle.cousin # == 'import ..uncle.cousin'
... while the notation here is intuitive (to a python programmer), but is not concise. I still favor this syntax to the former syntax.
I like 'pkg' better than my initial suggestion ('parent'). It's more aesthetically pleasing. :)
-- Devin devin at whitebread.org http://www.whitebread.org/
- Previous message: [Python-Dev] Relative import
- Next message: [Python-Dev] Re: Relative import
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]