RFC: Assignment as expression (pre-PEP)
Bruno Desthuilliers
bdesth.quelquechose at free.quelquepart.fr
Thu Apr 5 19:52:12 EDT 2007
TimeHorse at gmail.com a écrit :
> I would like to gauge interest in the following proposal:
>
> Problem:
>
> Assignment statements cannot be used as expressions.
This is by design.
> Performing a list of mutually exclusive checks that require data
> processing can cause excessive tabification. For example, consider
> the following python snipet...
>
> temp = my_re1.match(exp)
> if temp:
> # do something with temp
> else:
> temp = my_re2.match(exp)
> if temp:
> # do something with temp
> else:
> temp = my_re3.match(exp)
> if temp:
> # do something with temp
> else:
> temp = my_re4.match(exp)
OMG.
actions = [
(my_re1, do_something_with_temp1),
(my_re2, do_something_with_temp2),
(my_re3, do_something_with_temp3),
(my_re4, do_something_with_temp4),
]
for my_re, do_something_with in actions:
temp = my_re.match(exp):
if temp:
do_something_with(temp)
break
Having full-blown anonymous functions or Ruby/Smalltalk-like code blocks
would be much more interesting IMHO.
More information about the Python-list
mailing list