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

Steven D. Majewski sdm7g at
Fri Nov 9 00:03:45 CET 2001

On Thu, 8 Nov 2001, Rainer Deyke wrote:

> <James_Althoff at> wrote in message
> news:mailman.1005256814.9657.python-list at
> >
> > 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)
> I like it.  I guess that just goes to show how non-Pythonic I am.
> Seriously, I don't see how this is worse or less Pythonic than, say, 'for
> line in file'.

If "for i in 10:" was legal, I'ld guess it meant the same thing as
"for i in [10]:" or "for i in (10,):"

A file *IS* a sequence -- although you could just as easily slice it
by characters as lines -- or by any arbitrary object for binary files,
as Pascal does. If the integer 10 suggests any sort of sequence, it's
the singleton sequence containing: 10.

-- Steve

More information about the Python-list mailing list