C-like assignment expression?

sturlamolden sturlamolden at yahoo.no
Wed May 21 13:56:10 EDT 2008


On May 21, 11:38 am, boblat... at googlemail.com wrote:

> if (match = my_re1.match(line):
>   # use match
> elsif (match = my_re2.match(line)):
>   # use match
> elsif (match = my_re3.match(line))
>   # use match
>
> ...buy this is illegal in python.


Assignment expressions is disallowed in Python to protect against a
very common bug in C/C++ programs, the (accidental) confusion of

   if (match = my_re1.match(line))

with

   if (match == my_re1.match(line))

or vice versa.











More information about the Python-list mailing list