PEP 284, Integer for-loops

James_Althoff at i2.com James_Althoff at i2.com
Fri Mar 8 19:56:42 EST 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).

David Mertz:
|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 various contributors).
|
|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
|code.


I just did the same for a small section of our code.  My quick little scan
turned up 293 uses of [x]range.  Most -- as in nearly all -- of them are in
for-loops and *are* used in conjunction with the indices of collections.

Our mileage might be different from others because our use of Jython is for
large-scale, shipping, production-level, commercial applications rather
than for small, throw-away scripts or core-language libraries.  Also (as
mentioned) we use Jython and have to deal with tables and other kinds of
collections written in Java outside the scope of core C-Python.  So I guess
we lose.

Jim Althoff
Senior Vice President
i2 Technologies, Inc.






More information about the Python-list mailing list