Nested Mapping

Raymond Hettinger raymond.activestate at gmail.com
Fri Oct 22 23:35:31 CEST 2010


On Oct 21, 6:13 pm, Paul Rubin <no.em... at nospam.invalid> wrote:
> Raymond Hettinger <pyt... 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().

Children point to parents
but the parents don't know about the children.



> >> 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"]

I'm curious what you would expect (and find useful)?


Raymond



More information about the Python-list mailing list