[docs] [issue31982] 8.3. collections — Container datatypes
Sasha Kacanski
report at bugs.python.org
Wed Nov 8 11:10:51 EST 2017
New submission from Sasha Kacanski <skacanski at gmail.com>:
Hi,
In ChainMap example
c = ChainMap() # Create root context
d = c.new_child() # Create nested child context
e = c.new_child() # Child of c, independent from d
e.maps[0] # Current context dictionary -- like Python's locals()
e.maps[-1] # Root context -- like Python's globals()
e.parents # Enclosing context chain -- like Python's nonlocals
d['x'] # Get first key in the chain of contexts
d['x'] = 1 # Set value in current context
d['x'] - will raise key does not exist error
so simple fix is to flip last two lines...
I know, possibly anal but look love Python and would like to help new folks to not get confused if they play with example in cPython shell...
--best
----------
assignee: docs at python
components: Documentation
messages: 305876
nosy: Sasha Kacanski, docs at python
priority: normal
severity: normal
status: open
title: 8.3. collections — Container datatypes
versions: Python 3.6
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue31982>
_______________________________________
More information about the docs
mailing list