Hi all, Many languages allow assignment expressions in if conditions. (Perl, PHP, Ruby, C, etc..) I know that this was dismissed by guido because it can lead to mistakes. And i can support that. However in some situations it might be required because you have to nest if blocks and regular expressions for example:: while pos < text_length: if match = name_re.match(text, pos): pos = match.end() do_something(match) elif match = digit_re.match(text, pos): pos = match.end() do_something(match) else: pos += 1 Well. But that would require an assignment. Why not use the "as" keyword introduced in python2.5 with the future import:: while pos < text_length: if name_re.match(text, pos) as match: pos = match.end() do_something(match) elif digit_re.match(text, pos) as match: pos = match.end() do_something(match) else: pos += 1 Advantages: Still no assignment expression, no additional keyword, simple to understand. Regards, Armin
participants (8)
-
Armin Ronacher
-
Georg Brandl
-
Greg Ewing
-
Josiah Carlson
-
Larry Hastings
-
Sam
-
Scott Dial
-
Talin