[Python-Dev] Syntax suggestion for imports

Drew Perttula drewp at bigasterisk.com
Fri Jan 4 07:51:00 CET 2008


Simon Percivall wrote:
> Wouldn't a (stdlib) function suffice in the cases where this is needed?
> 
> ET = import_with_alternative("xml.etree.CElementTree", "cElementTree",  
> "elementtree.ElementTree")
> 
> It's not as elegant, but it's easier than status quo.
> 

I like that direction a lot better than the syntax proposals. This isn't 
the kind of thing that needs to get composed into bigger expressions, 
which is where clever uses of operators really shine. Here, I think the 
operators were subtracting clarity and your named function was adding 
clarity.

When I saw the OP, I actually wondered why people whose codebases are 
"filled" with the same try/except block over and over hadn't just 
written their own import_with_alternative function in the first place. 
If I wanted half my lines of code to be devoted to control flow and 
block structure, I'd write in one of those curly-brace languages :)



More information about the Python-Dev mailing list