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


Groups > comp.lang.python > #112037

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

Path csiph.com!news.mixmin.net!news.unit0.net!fu-berlin.de!uni-berlin.de!not-for-mail
From eryk sun <eryksun@gmail.com>
Newsgroups comp.lang.python
Subject Re: TypeError: '_TemporaryFileWrapper' object is not an iterator
Date Sat, 30 Jul 2016 01:17:22 +0000
Lines 30
Message-ID <mailman.39.1469841485.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> <CACL+1atsBtLNdifUPuo3E=gbb_hOUiiUT7Vpmv0UppQ4UeGhCA@mail.gmail.com>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
X-Trace news.uni-berlin.de JRIUb5ZojpWvhjMSY57YNAx/TlX3M5WsyrI1iMrFfqyw==
Return-Path <eryksun@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; '(python': 0.05; 'python3': 0.05; "subject:' ": 0.07; 'expectation': 0.09; 'underlying': 0.09; 'python': 0.10; 'subject:not': 0.11; '2016': 0.16; 'iterable,': 0.16; 'iteration': 0.16; 'iterator': 0.16; 'iterators': 0.16; 'low-level': 0.16; 'pointer,': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'reedy': 0.16; 'subject:object': 0.16; 'wrote:': 0.16; '>>>': 0.20; 'windows': 0.20; 'maintains': 0.22; 'am,': 0.23; 'seems': 0.23; 'header:In-Reply-To:1': 0.24; "doesn't": 0.26; 'fri,': 0.27; 'message-id:@mail.gmail.com': 0.27; 'sequence': 0.27; 'function': 0.28; 'pointer.': 0.29; 'reset': 0.29; 'class.': 0.30; 'especially': 0.32; 'point': 0.33; 'useful': 0.33; 'problem': 0.33; 'common': 0.33; 'file': 0.34; 'received:google.com': 0.35; 'to:addr:python-list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'operating': 0.37; 'files': 0.38; 'to:addr:python.org': 0.40; 'called': 0.40; 'some': 0.40; 'skip:n 10': 0.62; 'jul': 0.72; 'idiom': 0.84; 'pardon': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=Koe12Mj8Q53AFgcBQDVnLdM8MigHN7o5YOZbbbert98=; b=ajLCU6YnDtoproVYzTbkGh4tr2BJJwNXUEyTXL91EmXQGtfLV72fR6ScDmiphFBWXe MUO3gYMzKC+t3Vr4HwG1SoDavz+rVLtuVVk3nEBLE6JHRloEm+l0goi5JR5yzM2wZS0k 1VrEQom+OTZOt+Rt2wZaVmBI+5zJ5G/XeBb9hik/ERjTicVF03+4LT9Jg46EAhzbKceC bZ29XbNt/eTR05LrHqMzfQaBifcCarGdWvoGC1CTSQtyQ4bFczdISU4CGcT7x1nyfCnr HiWEykaM2tC3STc79NVM/FdO2F6xDVshggl921rMbtDwWOy95yWejJWVMhrk0K9AboRk 0FmQ==
X-Google-DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=Koe12Mj8Q53AFgcBQDVnLdM8MigHN7o5YOZbbbert98=; b=WfqUSBWmQ+thGUJH9d0gvYGbkO2VvmgWep12Donkit+uGuSKKs3IuYYmbwcUB09io/ mkTUH69ypvLOT8mCZzD75QRLnsiGi7G6nKyIDXPoznKYYutGjCsXKOpQhyKBLqG6ALPS 7ZGO83ne5yxKEEutk+4aBruvZzWIfCuYoVYBL8ndyEcEeIxrhZuvzAA2c7ZL70wkHIZs U5Je8Zki4uks2p0lFS1pG2LODcUetHGZDGCeT/D4cGCnFhEUn/qKgxD5VfkDioKc+dzm 4QQ/beoD1uV7lZo2MLj5LOR2+AHiMG8d+v/GsuaHTMyDULA7Kw6e16ERLxMRx+nYAZmf veXQ==
X-Gm-Message-State AEkoouurKW099UDmEV+MaWW8wwBr4OmjFYfnWLvHwptF5KfBO0hFd99z03rC7L/z/Z6F+QBwivgN30Souw7O4g==
X-Received by 10.107.56.87 with SMTP id f84mr47128708ioa.188.1469841482545; Fri, 29 Jul 2016 18:18:02 -0700 (PDT)
In-Reply-To <nngb4b$rus$1@ger.gmane.org>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.22
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID <CACL+1atsBtLNdifUPuo3E=gbb_hOUiiUT7Vpmv0UppQ4UeGhCA@mail.gmail.com>
X-Mailman-Original-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>
Xref csiph.com comp.lang.python:112037

Show key headers only | View raw


On Fri, Jul 29, 2016 at 7:34 PM, Terry Reedy <tjreedy@udel.edu> wrote:
> 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.

Yes, using a generator function is a simple way to create multiple
iterators of an iterable, which is especially useful for a sequence
that's independently reiterable. However a Python io file is its own
iterator because it's based on a synchronous operating system File
that maintains a file pointer. (Python io files don't support Windows
asynchronous file access, which doesn't update the File pointer, and
even the low-level _winapi and _overlapped implementations don't
support this.)

In this case there's no point that I can see in using a generator
function for __iter__. If you call iter() again on the
tempfile._TemporaryFileWrapper, it doesn't produce a new iteration of
the underlying file until seek(0) is called to reset the file pointer.
So __iter__ may as well  return `self` and have __next__ proxy
next(self.file).

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: TypeError: '_TemporaryFileWrapper' object is not an iterator eryk sun <eryksun@gmail.com> - 2016-07-30 01:17 +0000

csiph-web