summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorEthan Furman <ethan@stoneleaf.us>2013-06-28 21:02:34 (GMT)
committerEthan Furman <ethan@stoneleaf.us>2013-06-28 21:02:34 (GMT)
commit3fe70b4acc0738041f4617ce76f902e213a51139 (patch)
tree23e2069a66478578ffbe5a7aeb886d0c32f38e6a /Doc
parentcf873c699fba949d7c0d2dc25b643a16bf6a4dcf (diff)
downloadcpython-3fe70b4acc0738041f4617ce76f902e213a51139.zip
cpython-3fe70b4acc0738041f4617ce76f902e213a51139.tar.gz
cpython-3fe70b4acc0738041f4617ce76f902e213a51139.tar.bz2
Added example to enum docs show access to name and value attributes of enum members.
Diffstat (limited to 'Doc')
-rw-r--r--Doc/library/enum.rst12
1 files changed, 10 insertions, 2 deletions
diff --git a/Doc/library/enum.rst b/Doc/library/enum.rst
index ae0498c..8979181 100644
--- a/Doc/library/enum.rst
+++ b/Doc/library/enum.rst
@@ -87,8 +87,8 @@ Enumeration members are hashable, so they can be used in dictionaries and sets::
True
-Programmatic access to enumeration members
-------------------------------------------
+Programmatic access to enumeration members and their attributes
+---------------------------------------------------------------
Sometimes it's useful to access members in enumerations programmatically (i.e.
situations where ``Color.red`` won't do because the exact color is not known
@@ -106,6 +106,14 @@ If you want to access enum members by *name*, use item access::
>>> Color['green']
<Color.green: 2>
+If have an enum member and need its :attr:`name` or :attr:`value`::
+
+ >>> member = Color.red
+ >>> member.name
+ 'red'
+ >>> member.value
+ 1
+
Duplicating enum members and values
-----------------------------------