Python language hack for C-style programmers [DO NOT USE!] :-)
rosuav at gmail.com
Thu Mar 27 17:12:25 CET 2014
On Fri, Mar 28, 2014 at 3:08 AM, Tim Chase
<python.list at tim.thechases.com> wrote:
> So when I stumbled upon this horrific atrocity of language abuse and
> scope leakage, I thought I'd share it.
> if [m for m in [regex.match(some_string)] if m]:
> And presto, assignment in an if-statement.
And presto, it doesn't work in Python 3:
>>> if [m for m in  if m]:
Traceback (most recent call last):
File "<pyshell#2>", line 2, in <module>
NameError: name 'm' is not defined
So definitely don't do it. :)
More information about the Python-list