[Python-ideas] import fallback syntax

Philip Jenvey pjenvey at underboss.org
Thu Mar 8 20:06:45 CET 2012


On Mar 8, 2012, at 9:55 AM, 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?

It's been proposed before, you might want to read this old thread:

http://mail.python.org/pipermail/python-dev/2008-January/075788.html

--
Philip Jenvey




More information about the Python-ideas mailing list