x[i] as loop variable

Erik Max Francis max at alcyone.com
Thu Oct 23 21:15:57 EDT 2003


Raymond Hettinger wrote:

> In general, it should never be used unless you're trying to obfuscate
> your code.  It is a long standing, unintended by-product of the
> grammar that any lvalue can be used as a loop variable.  Most folks
> aren't aware of it and everyone is better off not knowing about it.
> In fact, I wish it hadn't come-up at all because someone will read
> about it and adopt the atrocity as their new favorite style.

Yes, I encountered this when implementing iterative control markups for
EmPy.  I was quite surprised that such syntaxes were allowed in Python;
I'd never seen them or heard of them being used, and only through an
experiment did I realize much to my surprise that, as you say, any
lvalue can be used as the iteration variable.

Even though the EmPy control markups are intended to mimic the native
Python control structures as closely as possible (the pinciple of least
surprise), needless to say, I got no complaints about deliberately
deviating from Python in this respect; in EmPy, iteration variables must
be simple variable names and nothing more.

-- 
   Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/
 __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
/  \ Pick the roses from the thorns / Wash with waters of the storms
\__/  Chante Moore




More information about the Python-list mailing list