How to do this in Python...

Erik Max Francis max at alcyone.com
Tue Jan 28 01:54:07 EST 2003


Carl Banks wrote:

> I suppose "for i in [1]:" isn't as transparent as "while 1:", ...

ObTwoPointThree:  Or while True: ...!  :-)

> ... but
> idiom it's used for isn't as common.

Maybe it's just me, but I think the [1] (namely, the list that contains
a single 1) is the most confusing part, since it makes the construct
almost looks like there's something more going on behind it, and someone
really wants to do something with the variable i and the value 1.  I
would recommend something more like:

	for dummy in [None]:
	    ...

for this purpose.  This, at least to me, more clearly declares "this
variable is really not used for anything and neither is the value it
contains."

In fact, I can think of one area in my code where I do a sequence of
assign and tests (using regular expressions no less), I'm tempted to use
the pattern myself.  (At present it's at the top level of a function, so
it just returns when it finds a match and after it acts on it.)

-- 
 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/  \ Peace with a cudgel in hand is war.
\__/ (a Portugese proverb)
    Blackgirl International / http://www.blackgirl.org/
 The Internet resource for black women.




More information about the Python-list mailing list