Nested Mapping
Paul Rubin
no.email at nospam.invalid
Thu Oct 21 21:13:24 EDT 2010
Raymond Hettinger <python at rcn.com> writes:
> The c.parent.parent.parent chain finds successive enclosing contexts:
I was asking about finding the child contexts, not the parents. This is
analogous to how you can find the keys in a dict with dict.keys().
>> One question: what should
>>
>> c["foo"] = 7
>> d = c.new_child()
>> del d["foo"]
>>
>> do?
>
> By default, it raises a KeyError because 'foo' is not in the current
> context. But if enable_nonlocal is set to True, it removes 'foo' from
> the parent context, c.
I would not have guessed either of those behaviors. What happens on
c["foo"] = 7
d = c.new_child()
d["foo"] = 8
del d["foo"]
print c["foo"], d["foo"]
More information about the Python-list
mailing list