It's ...

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Sat Jun 27 02:32:12 EDT 2009


En Thu, 25 Jun 2009 14:07:19 -0300, Angus Rodgers <twirlip at bigfoot.com>  
escribió:

> On Thu, 25 Jun 2009 17:56:47 +0100, I burbled incoherently:
>
>> [...] does the new feature,
>> by which a file becomes iterable, operate by some kind of coercion
>> of a file object to a list object, via something like x.readlines()?
>
> Sorry to follow up my own post yet again (amongst my weapons is
> a fanatical attention to detail when it's too late!), but I had
> better rephrase that question:
>
> Scratch "list object", and replace it with something like: "some
> kind of iterator object, that is at least already implicit in 2.1
> (although the term 'iterator' isn't mentioned in the index to the
> 2nd edition of Beazley's book)".  Something like that!  8-P

Iterators were added in Python 2.2. An iterator is an object that can be  
iterated over; that is, an object for which "for item in some_iterator:  
..." works.
Files are their own iterators, yielding one line at a time.
See PEP 234 http://www.python.org/dev/peps/pep-0234/

-- 
Gabriel Genellina




More information about the Python-list mailing list