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