Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #41160
| Path | csiph.com!usenet.pasdenom.info!news.albasani.net!.POSTED!not-for-mail |
|---|---|
| From | Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> |
| Newsgroups | comp.lang.python |
| Subject | Re: del not working for (exhausted) dict iterable value (Python 3.3) |
| Date | Wed, 13 Mar 2013 05:02:42 +0100 |
| Organization | A newly installed InterNetNews server |
| Lines | 31 |
| Message-ID | <khotp3$sja$1@r03.glglgl.gl> (permalink) |
| References | <2879f537-1666-46f7-abbf-38204d8184c2@googlegroups.com> <0809a262-494f-46d6-910a-909a06e2aa92@m9g2000pby.googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Trace | news.albasani.net WI5CzK6vRj4XOZJAgh4CiqeU5f0TBzLO/7b6OCgUpaf/lxhQycx9NXQlMimkQ1lnsIsCE2xfP0/ql8ySY09GIAe98u3i48qprBoJ0DqZUgS+42N8dzWXXczN4ZCmYD8Y |
| NNTP-Posting-Date | Wed, 13 Mar 2013 04:10:02 +0000 (UTC) |
| Injection-Info | news.albasani.net; logging-data="Bqo8bxpeK6N9UGHYybwFmuhEnJeNx9FcetgSiJ3uosLxebADVnflE1XUFEmp2IdaLsqAw3xk7PHCfpqNDRHD4+8JjhNPzeDbdKSaQ2/1lwkeS8FeEIFaEJ2ESUvCCZGGO1hYbshelQf/hGBPYjXPFjURLC5bPU77IhMNixOcOrQ="; mail-complaints-to="abuse@albasani.net" |
| User-Agent | Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/20130215 Thunderbird/17.0.3 |
| In-Reply-To | <0809a262-494f-46d6-910a-909a06e2aa92@m9g2000pby.googlegroups.com> |
| Cancel-Lock | sha1:nMxejzt3L2DM+2Oqh9n/08kMvNA= |
| Xref | csiph.com comp.lang.python:41160 |
Show key headers only | View raw
Am 12.03.2013 06:52 schrieb alex23:
> You're effectively doing this:
>
>>>> event = dict(Items=[1,2,3])
>>>> for e in event['Items']:
> ... del event['Items']
> ...
> Traceback (most recent call last):
> File "<stdin>", line 2, in <module>
> KeyError: 'Items'
>
> You want to move your del statement up an indentation level so it
> happens after the iterator is actually exhausted, and not after the
> first iteration.
Just to be clear: Exhausting the iterator is not the problem, as I
thought as well at the first glance.
The problem is the fact that the loop body tuns multiple times - and so
does the del statement. A
event = dict(Items=[1,2,3])
for e in event['Items']:
if 'Items' in event: del event['Items']
runs perfectly, as the iterable is transformed to an iterator at the
very start of the loop.
Thomas
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
del not working for (exhausted) dict iterable value (Python 3.3) Nick Mellor <thebalancepro@gmail.com> - 2013-03-11 22:35 -0700
Re: del not working for (exhausted) dict iterable value (Python 3.3) alex23 <wuwei23@gmail.com> - 2013-03-11 22:52 -0700
Re: del not working for (exhausted) dict iterable value (Python 3.3) Nick Mellor <thebalancepro@gmail.com> - 2013-03-12 15:40 -0700
Re: del not working for (exhausted) dict iterable value (Python 3.3) Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2013-03-13 05:02 +0100
csiph-web