conatraints on "for" magic?

Moshe Zadka moshez at math.huji.ac.il
Wed Jul 26 04:10:00 EDT 2000


On 26 Jul 2000, (Greg Weeks) wrote:

> Initially I learned that
> 
>     for x in seq:
> 	<do stuff>
> 
> required seq to be a sequence.  But then I saw the code:
> 
>     import fileinput
>     for line in fileinput.input():
> 	<do stuff>
> 
> How did the implementer of the "fileinput" module convince the "for"
> construct that fileinput.input() was a sequence?

Implemented the __getitem__ method. Read more about operator overloading:
I'm sure it's in PER

--
Moshe Zadka <moshez at math.huji.ac.il>
There is no IGLU cabal.
http://advogato.org/person/moshez





More information about the Python-list mailing list