On Mar 12, 3:35 pm, Nick Mellor <thebalance...@gmail.com> wrote:
> event['Items'] is an exhausted (all used up) iterable.
>
> Now I do the following (lines 142-4):
>
>             event.update({'Attributes': filtered_attributes})
>             del event['Items']
>             yield event
>
> and get a KeyError on the del statement.
>
> Is there some deep design in Python here, that it won't delete a
> dict value that's an (exhausted) iterator, or have I found a bug?

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.
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to