classification
Title: 8.3. collections — Container datatypes
Type: Stage:
Components: Documentation Versions: Python 3.6
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: rhettinger Nosy List: Sasha Kacanski, docs@python, rhettinger
Priority: low Keywords:

Created on 2017-11-08 16:10 by Sasha Kacanski, last changed 2017-11-08 20:50 by Sasha Kacanski.

Messages (3)
msg305876 - (view) Author: Sasha Kacanski (Sasha Kacanski) Date: 2017-11-08 16:10
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
msg305903 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2017-11-08 20:41
I will flip the two because there is not downside.  However, the table of wasn't intended to be a sequential example (that's why there is no data or display of result).  Instead, it was just meant to be table of typing-this-does-that.
msg305905 - (view) Author: Sasha Kacanski (Sasha Kacanski) Date: 2017-11-08 20:50
Agree, and I know.

On Nov 8, 2017 3:41 PM, "Raymond Hettinger" <report@bugs.python.org> wrote:

>
> Raymond Hettinger <raymond.hettinger@gmail.com> added the comment:
>
> I will flip the two because there is not downside.  However, the table of
> wasn't intended to be a sequential example (that's why there is no data or
> display of result).  Instead, it was just meant to be table of
> typing-this-does-that.
>
> ----------
> assignee: docs@python -> rhettinger
> nosy: +rhettinger
> priority: normal -> low
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <https://bugs.python.org/issue31982>
> _______________________________________
>
History
Date User Action Args
2017-11-08 20:50:58Sasha Kacanskisetmessages: + msg305905
2017-11-08 20:41:45rhettingersetpriority: normal -> low

nosy: + rhettinger
messages: + msg305903

assignee: docs@python -> rhettinger
2017-11-08 16:10:51Sasha Kacanskicreate