[Python-Dev] Relative import
Charles Hixson
charleshixsn at earthlink.net
Tue Dec 23 10:54:46 EST 2003
Guido van Rossum 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
>>
>> searching could be 'absolute' '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.
>>
>> -jackdied
>>
>> ps, I like the second version better but it is less like the current
>> version,
>> which is a drawback.
>>
>
>
> This got several encouraging responses, so I have to consider it.
>
> Unfortunately it looks like 'searching' would have to become a
> reserved word; if we use the same trick we used to avoid making 'as' a
> reserved word, that would be too confusing to decode in the code
> generator. The HOW could be just an identifier then.
>
> I'm not sure how well it'll read in actual examples. Let's try.
> Adapting an example from Opal that was used here before...
>
> from COGS import generate searching relative
>
> To me, that looks a lot like someone left the commas out of
>
> from COGS import generate, searching, relative
>
> In general I'm not a big fan of "wordy" clauses like this -- they work
> better in languages like SQL or COBOL because those are case-sensitive
> so you can use a difference in capitalization there; there the former
> would be
>
> FROM COGS IMPORT generate SEARCHING RELATIVE
>
> (using imaginary syntax) while the latter would be
>
> FROM COGS IMPORT generate, searching, relative
>
> while in Python the long sequence of lowercase words becomes a blur.
>
> So if the two alternatives are simply 'searching absolute' and
> 'searching relative', with the default being 'searching absolute' in
> Python 3.0 (but the current ambiguous search in Python 2.x) I'd still
> prefer making the distinction with "from ...MODULE" vs. "from MODULE"
> rather than with a searching clause. And I still prefer the
> single-dot syntax over three dots, because it can be used to spell
> importing from the parent or grandparent package explicitly.
>
> A separate suggestion is to switch from "from X import Y" to "import Y
> from X". This seems a gratuitous change even if it reads or edits
> marginally better. Now's not the time to tinker with marginal stuff
> -- that should've been done 10 years ago.
>
> --Guido van Rossum (home page: http://www.python.org/~guido/)
>
> _______________________________________________
> Python-Dev mailing list
> Python-Dev at python.org
> http://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe:
> http://mail.python.org/mailman/options/python-dev/charleshixsn%40earthlink.net
>
>
>
>
Not necessarily. import could be a special function that doesn't need
parentheses around it's arguments or comma separators. That could be
syntax sugar for:
import (names, namedAs, fromModule, searchmethod) or
import (names =[theNames], namedAd=[localNames], fromModule=fromModule,
searchMethod=upFromCurrent)
OTOH, to me it looks more like Smalltalk than like Python. An explicit
import function without special sugar looks more Pythonic. (But that
would break backward compatibility.)
Perhaps the current method could be deprecated, and an import function
be the replacement?
More information about the Python-Dev
mailing list