PEP 284, Integer for-loops
David Mertz, Ph.D.
mertz at gnosis.cx
Sat Mar 9 01:11:25 CET 2002
Roy Smith <roy at panix.com> wrote previously:
|I just took a look at some random collection of python code I've got laying
|around, totaling 6100 lines. I've got 85 for loops, 12 of which use range,
|the other 73 don't. What's even more interesting is that of the 12 ranges,
|11 of them are in a single file; the only file of the collection which I
|didn't write (and which I consider pretty ugly code).
I decided to do the same test (more or less). A current snapshot of my
"Gnosis XML Utilities" has 3100 lines (written largely by me, with
There are *4* uses of [x]range() in 'for' loops. One is a test case
that just uses 'range(500)' to do something "a bunch of times". One of
the remaining three is 'range(1,len(fields),2)', which doesn't lend
itself easily to the integer-iterator proposal. There are *two*
occurrences of 'range(len(member))', which I agree are slightly awkward
to write and read.
There are actually more uses of the range() function to indicate ranges
of ASCII values than in the loop context, in this particular lump of
More information about the Python-list