[Python-Dev] Relative import

Tim Peters tim.one at comcast.net
Fri Dec 19 23:32:45 EST 2003


[Jack Diederich]
>> ...
>> 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
>>
>> searching could be 'asbolute' 'relative' or any of the other
>> suggested words.  If you wanted to get fancy it could be a list, if
>> it isn't a list people who truly care could cascade try/except on
>> ImportError.

[Barry Warsaw]
> I want to think about that more, but at first glance, it has some
> appeal.  Neat!

Ditto.  I think Jack's on to something there.  I particularly like the
second form, as it's an ongoing irritation to me that some imports begin
with "from" and others with "import".  In the current "from" form, the most
important thing to me is almost never the module I'm importing the thing
from, but (of course) the thing I'm importing.

Going from

    import math

to

    import sin from math

(or vice versa) is also an easier edit than from

    import math

to

    from math import sin

(because the former doesn't require transposition).

Adding a distinct clause to influence search details seems downright
Pythonic.  Maybe *too* Pythonic <wink>.




More information about the Python-Dev mailing list