Proposal for a modified import mechanism.

Rainer Deyke root at
Sat Nov 10 21:17:04 CET 2001

"Frederic Giacometti" <frederic.giacometti at> wrote in message
news:mailman.1005416114.20092.python-list at
> I'd rather introduce a __parent__ module attribute (in addition to the
> existing __name__) so that, for instance, the following would do your job:
> from __parent__.__parent__.toto import something

This wouldn't work without additional changes to the import mechanism, since
the bindings of names are not used to resolve imports.  Let's not add any
more special cases.

> I'm personnally against anything that enlarges the search path uselessly;
> because the obvious reason of increased name space collision, increased
> run-time overhead etc...

The best way to avoid name collisions is to keep top-level names at an
absolute minimum by placing modules in a deep hierarchy.  Run-time overhead
may also be reduced this way, since many operating systems do a linear
search over all files in a directory when opening a file.  The best way to
support deep module hierarchies is to make relative imports as painless as

Rainer Deyke (root at
Shareware computer games           - 
"In ihren Reihen zu stehen heisst unter Feinden zu kaempfen" - Abigor

More information about the Python-list mailing list