[Python-ideas] import fallback syntax

Westley Martínez anikom15 at gmail.com
Fri Mar 9 00:05:32 CET 2012


On Thu, Mar 08, 2012 at 09:55:35AM -0800, Chris Withers wrote:
> Hi All,
> 
> I see a lot of Python like this:
> 
> try:
>   from cDecimal import Decimal
> except ImportError:
>   from decimal import Decimal
> 
> ...and nest deeper if you're talking about ElementTree.
> 
> How about some syntactical sugar to make this less obnoxious:
> 
> from cDecimal or decimal import Decimal
> 
> from x.y.z import X as X or
>      a.b.z import Y as X or
> 
> what do people think?
> 
> Chris

I seem to recall something like this proposed some time ago.  I believe
one argument against it was that or would have to change its meaning
based on context.  Changes to the language need to make expressing a
particular idiom possible, simpler, and more readable.  To me the
proposed expression is less clear, and the current method is very clear
and works quite well.

-1



More information about the Python-ideas mailing list