New syntax for blocks

r rt8396 at gmail.com
Tue Nov 10 20:23:35 CET 2009


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. However i have no idea how much
trouble the implementation would be? Now i know you could write a
function and do the following to forgo the indention...

value = something_that_returns_value()
if not value:
    return
#do something with value

....but that's even uglier and i would like the construct to work in
both sinlge 'ifs' and also conditional's Now some might say...Whats
the big deal, you only save one line of code?...True, but if you can
save one line of code 100 or 1000 times how many lines of code is that
my inquisitive friend?  ;-)



More information about the Python-list mailing list