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

Rainer Deyke root at rainerdeyke.com
Thu Nov 8 21:59:32 EST 2001


"Steven D. Majewski" <sdm7g at minsky.med.virginia.edu> wrote in message
news:mailman.1005260651.24404.python-list at python.org...
> 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,):"

Guessing is no substitute for reading the docs, even in Python.

> 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.


--
Rainer Deyke (root at rainerdeyke.com)
Shareware computer games           -           http://rainerdeyke.com
"In ihren Reihen zu stehen heisst unter Feinden zu kaempfen" - Abigor





More information about the Python-list mailing list