Zen of Python

Alex Martelli aleaxit at yahoo.com
Sat Jan 22 03:50:36 EST 2005


Dave Benjamin <dave.benjamin at gmail.com> wrote:

> Can we get a show of hands for all of those who have written or are 
> currently maintaining code that uses the leaky listcomp "feature"?

"Have written": guilty -- basically to show how NOT to do things.
"Currently maintaining": you _gotta_ be kidding!-)


> I guess I've been peripherally aware of it, but I almost always use 
> names like "x" for my loop variables, and never refer to them 
> afterwards. If Python were to change in this regard, I don't think it
> would break any Python code that I've ever written or maintained...

If it changed the semantics of for-loops in general, that would be quite
inconvenient to me -- once in a while I do rely on Python's semantics
(maintaining the loop control variable after a break; I don't recall if
I ever used the fact that the variable is also maintained upon normal
termination).

(musing...): I think the reason there's no real use case for using a
listcomp's control variable afterwards is connected to this distinction:
listcomps have no `break'...


Alex



More information about the Python-list mailing list