Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #69204 > unrolled thread

Re: Python language hack for C-style programmers [DO NOT USE!] :-)

Started byChris Angelico <rosuav@gmail.com>
First post2014-03-28 03:12 +1100
Last post2014-03-28 03:12 +1100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Python language hack for C-style programmers [DO NOT USE!] :-) Chris Angelico <rosuav@gmail.com> - 2014-03-28 03:12 +1100

#69204 — Re: Python language hack for C-style programmers [DO NOT USE!] :-)

FromChris Angelico <rosuav@gmail.com>
Date2014-03-28 03:12 +1100
SubjectRe: Python language hack for C-style programmers [DO NOT USE!] :-)
Message-ID<mailman.8624.1395936753.18130.python-list@python.org>
On Fri, Mar 28, 2014 at 3:08 AM, Tim Chase
<python.list@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]:
>     do_something(m)
>
> And presto, assignment in an if-statement.

And presto, it doesn't work in Python 3:

>>> if [m for m in [5] if m]:
    print(m)

Traceback (most recent call last):
  File "<pyshell#2>", line 2, in <module>
    print(m)
NameError: name 'm' is not defined

So definitely don't do it. :)

ChrisA

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web