Return value of an assignment statement?

Steve Holden steve at holdenweb.com
Thu Feb 21 18:52:21 EST 2008


mrstephengross 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)
> 
> Yep, this is exactly what I am (was) trying to do. Oh well.... Any
> clever ideas on this front?
> 
The syntax is the way it is precisely to discourage that kind of clever 
idea. Of course, people nevertheless manage to work around the 
restriction to try and make their Python read like some other language 
they are more familiar with, and most of the time they get away with it.

The fat remains that in programming there *is* such a thing as being too 
clever, and Python's syntax deliberately discourages that.

regards
  Steve
-- 
Steve Holden        +1 571 484 6266   +1 800 494 3119
Holden Web LLC              http://www.holdenweb.com/




More information about the Python-list mailing list