[Python-ideas] except expression

Steven D'Aprano steve at pearwood.info
Fri Feb 21 01:46:47 CET 2014


On Fri, Feb 21, 2014 at 03:13:19AM +1100, Chris Angelico wrote:

> Proper layout of an expression-except that goes
> across multiple lines is still open for debate, but the most common
> cases will fit onto a single line anyway.

Put round brackets around the entire expression, then split where 
appropriate.

# Yes.
value = (some_long_expression except LongExceptionName:
         42)

# Or this
value = (some_long_expression 
         except LongExceptionName: 42)

# But not this:
value = (some_long
         expression except 
         LongExceptionName: 42)


-- 
Steven


More information about the Python-ideas mailing list