iters on ints? (reducing the need for range/xrange)

James_Althoff at i2.com James_Althoff at i2.com
Thu Nov 8 16:58:17 EST 2001


Now that the issue of transfinite cardinals has been fully resolved, isn't
it time for yet another unpopular-and-non-pythonic suggestion?  I believe
it is.

What if (in post-2.2) Python the tp_iter slot in the int type was defined
to return an xrange-like iterator such that one could do the following:

for i in 10:
    doSomething(i)

or, more realistically,

for rowIndex in table.getRowCount():
    doSomething(rowIndex)

instead of having to do the range(table.getRowCount()) thingie (or xrange,
if one prefers)?

(Following, here, the lead of the 2.2 mechanism for handling sequences in
for loops, etc.)

Fancy stuff could still be done with "range", of course.

(I never do fancy stuff),

Jim

ps. Or we could have another long thread about possible new syntax for
"1..10".

Or, explore ideas on the connection between Python and the continuum
hypothesis.






More information about the Python-list mailing list