On Oct 21, 6:13 pm, Paul Rubin <[email protected]> wrote: > Raymond Hettinger <[email protected]> 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 -- http://mail.python.org/mailman/listinfo/python-list
