iters on ints? (reducing the need for range/xrange)
ballabio at mac.com
Fri Nov 9 13:45:45 CET 2001
At 02:59 AM 11/9/01 +0000, Rainer Deyke wrote:
> > 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.
>The Pythons docs define "sequence" as something which supports the sequence
>interface. If 's' is a sequence, then 's[i]' is a defined operation that
>either returns a value or raises 'IndexError' (unless some other error
>occurs). A file isn't that.
We're talking iterators here, i.e., Python 2.2. iter(file) is a defined
operation which returns an iterator and "for line in file" is a valid
This said, while it makes sense in english to say "do this for every line
IN this file", it just doesn't sound right to me to say "do this for every
number IN 10"---even though I've been once familiar with the definitions of
the set of all integers. I'd rather say "for every number UP TO 10" but
that would mean introducing a new keyword which I'm not going to suggest,
not me, sir.
More information about the Python-list