New syntax for blocks

Robert Latest boblatest at yahoo.com
Tue Nov 10 15:08:14 EST 2009


r wrote:
> Forgive me if i don't properly explain the problem but i think the
> following syntax would be quite beneficial to replace some redundant
> "if's" in python code.
>
> if something_that_returns_value() as value:
>     #do something with value
>
> # Which can replace the following syntactical construct...
>
> value = something_that_returns_value()
> if value:
>     #do something with value
>
> i dunno, just seems to make good sense. You save one line of code but
> more importantly one indention level.

Typical case in matching regexes. But where do we save an indentation
level?

Also it's not the "if" that is (if at all) redundant here but the assignment. 

robert



More information about the Python-list mailing list