conatraints on "for" magic?

Greg Weeks weeks at golden.dtc.hp.com
Wed Jul 26 00:53:44 EDT 2000


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?

(In "Python ESSENTIAL REFERENCE" I don't find any way of creating class
instances that are recognized by "for" as sequences.)

Regards,
Greg



More information about the Python-list mailing list