diff options
author | Ezio Melotti <ezio.melotti@gmail.com> | 2014-10-28 14:07:14 (GMT) |
---|---|---|
committer | Ezio Melotti <ezio.melotti@gmail.com> | 2014-10-28 14:07:14 (GMT) |
commit | 788f2adeae7d4a59b801152a20a7cd05d215ba60 (patch) | |
tree | b73046ebbee5ff9175f80032f4dfe70f81f3d5e6 /Doc | |
parent | 670e8ff06c4c846cf1cefa3091939a8c0b26ac59 (diff) | |
download | cpython-788f2adeae7d4a59b801152a20a7cd05d215ba60.zip cpython-788f2adeae7d4a59b801152a20a7cd05d215ba60.tar.gz cpython-788f2adeae7d4a59b801152a20a7cd05d215ba60.tar.bz2 |
#22196: link to Enum in the nametuple documentation. Patch by Karmen Dykstra.
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/library/collections.rst | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/Doc/library/collections.rst b/Doc/library/collections.rst index f5fe12a..1651ef5 100644 --- a/Doc/library/collections.rst +++ b/Doc/library/collections.rst @@ -908,13 +908,14 @@ customize a prototype instance: >>> janes_account = default_account._replace(owner='Jane') Enumerated constants can be implemented with named tuples, but it is simpler -and more efficient to use a simple class declaration: +and more efficient to use a simple :class:`~enum.Enum` : >>> Status = namedtuple('Status', 'open pending closed')._make(range(3)) >>> Status.open, Status.pending, Status.closed (0, 1, 2) - >>> class Status: - open, pending, closed = range(3) + >>> from enum import Enum + >>> class Status(Enum): + ... open, pending, closed = range(3) * `Recipe for named tuple abstract base class with a metaclass mix-in <http://code.activestate.com/recipes/577629-namedtupleabc-abstract-base-class-mix-in-for-named/>`_ |