Return value of an assignment statement?
Paddy
paddy3118 at googlemail.com
Sat Feb 23 11:45:30 EST 2008
On 21 Feb, 23:33, "bruno.desthuilli... at gmail.com"
<bruno.desthuilli... at gmail.com> wrote:
> > What you can't do (that I really miss) is have a tree of assign-and-test
> > expressions:
>
> > import re
> > pat = re.compile('some pattern')
>
> > if m = pat.match(some_string):
> > do_something(m)
> > else if m = pat.match(other_string):
> > do_other_thing(m)
> > else:
> > do_default_thing()
>
> What you want is:
>
> for astring, afunc in ((some_string, do_something), (other_string,
> do_other_thing)):
> m = pat.match(astring)
> if m:
> afunc(m)
> break
> else:
> do_default_thing()
The Bruno transform? :-)
More information about the Python-list
mailing list