Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #112027
| From | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: TypeError: '_TemporaryFileWrapper' object is not an iterator |
| Date | 2016-07-29 15:34 -0400 |
| Message-ID | <mailman.35.1469820883.6033.python-list@python.org> (permalink) |
| References | <5798BECB.8030800@rece.vub.ac.be> <579B1720.9000103@rece.vub.ac.be> <CACL+1atRTLUVKsJ3minLQB8hX=91z+BoA9sQPzFFB=pKmF+Bow@mail.gmail.com> <nngb4b$rus$1@ger.gmane.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
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: TypeError: '_TemporaryFileWrapper' object is not an iterator Terry Reedy <tjreedy@udel.edu> - 2016-07-29 15:34 -0400
csiph-web