#22196: link to Enum in the nametuple documentation. Patch by Karmen Dykstra.
This commit is contained in:
parent
670e8ff06c
commit
788f2adeae
|
@ -908,13 +908,14 @@ customize a prototype instance:
|
||||||
>>> janes_account = default_account._replace(owner='Jane')
|
>>> janes_account = default_account._replace(owner='Jane')
|
||||||
|
|
||||||
Enumerated constants can be implemented with named tuples, but it is simpler
|
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 = namedtuple('Status', 'open pending closed')._make(range(3))
|
||||||
>>> Status.open, Status.pending, Status.closed
|
>>> Status.open, Status.pending, Status.closed
|
||||||
(0, 1, 2)
|
(0, 1, 2)
|
||||||
>>> class Status:
|
>>> from enum import Enum
|
||||||
open, pending, closed = range(3)
|
>>> class Status(Enum):
|
||||||
|
... open, pending, closed = range(3)
|
||||||
|
|
||||||
* `Recipe for named tuple abstract base class with a metaclass mix-in
|
* `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/>`_
|
<http://code.activestate.com/recipes/577629-namedtupleabc-abstract-base-class-mix-in-for-named/>`_
|
||||||
|
|
Loading…
Reference in New Issue