[Python-Dev] Relative import

Nick Coghlan ncoghlan at iinet.net.au
Sun Dec 21 08:16:58 EST 2003

Jack Diederich wrote:
> I like syntax that reads most important left-to-right, so what about
> from MODULE import NAMES as RENAME searching HOW
> or
> import NAMES as RENAME from MODULE searching HOW

This would work really well for any uses cases I can imagine having. It 
also has the following benefits:
1. No magic punctuation
2. People who don't need it, just never use a 'searching' clause
3. People encountering it for the first time have a clear flag letting 
them know something fancy is going on
4. These people have a word they can look up in the Python docs

I hadn't even thought of point 4 prior to considering Jack's proposal. 
If I encounter "import .fred.mary" in some python I didn't write, how 
the heck do I find out what it means?

> ps, I like the second version better but it is less like the current version,
> which is a drawback.

To head a little further down this sidetrack, the from version of 
'import' has puzzled me for a while:

A. from mypkg import foo
B. import mypkg.foo as foo

What, if any, are the semantic differences between A & B? Is it only 
that A2 works, and B2 doesn't?

A2. from mymodule import *
B2. import mymodule.*


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

More information about the Python-Dev mailing list