Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #112027 > unrolled thread

Re: TypeError: '_TemporaryFileWrapper' object is not an iterator

Started byTerry Reedy <tjreedy@udel.edu>
First post2016-07-29 15:34 -0400
Last post2016-07-29 15:34 -0400
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: TypeError: '_TemporaryFileWrapper' object is not an iterator Terry Reedy <tjreedy@udel.edu> - 2016-07-29 15:34 -0400

#112027 — Re: TypeError: '_TemporaryFileWrapper' object is not an iterator

FromTerry Reedy <tjreedy@udel.edu>
Date2016-07-29 15:34 -0400
SubjectRe: TypeError: '_TemporaryFileWrapper' object is not an iterator
Message-ID<mailman.35.1469820883.6033.python-list@python.org>
On 7/29/2016 7:59 AM, eryk sun wrote:
> On Fri, Jul 29, 2016 at 8:43 AM, Antoon Pardon
> <antoon.pardon@rece.vub.ac.be> wrote:
>>
>> The problem seems to come from my expectation that a file
>> is its own iterator and in python3 that is no longer true
>> for a NamedTemporaryFile.
>
> For some reason it uses a generator function for __iter__

This is a common idiom for having iterable.__iter__ return an iterator 
without writing and instanciating an iterator class.

> instead of
 > returning self, which would allow it to proxy the wrapped file's
> __next__ method. There may be a good reason for that design decision,
> but at the moment I don't see it,

For statements, usually the preferred way to iterator through an 
iterable, always call iter() on the iterable, before calling next on the 
result.  Collections are generally written as iterables.  If one is 
going to explicitly call next, then one should also call iter explicity.

> so I'd simply try the following:

Not nearly as simple as either calling iter() or using a simple for loop 
with a one-line body.  (See response to Antoon.)

[snip complex solution]

-- 
Terry Jan Reedy

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web