[Python-checkins] cpython: Added example to enum docs show access to name and value attributes of enum

ethan.furman python-checkins at python.org
Fri Jun 28 23:02:43 CEST 2013


http://hg.python.org/cpython/rev/446ae05de566
changeset:   84360:446ae05de566
user:        Ethan Furman <ethan at stoneleaf.us>
date:        Fri Jun 28 14:02:34 2013 -0700
summary:
  Added example to enum docs show access to name and value attributes of enum members.

files:
  Doc/library/enum.rst |  12 ++++++++++--
  1 files changed, 10 insertions(+), 2 deletions(-)


diff --git a/Doc/library/enum.rst b/Doc/library/enum.rst
--- a/Doc/library/enum.rst
+++ b/Doc/library/enum.rst
@@ -87,8 +87,8 @@
     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 @@
     >>> 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
 -----------------------------------

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list