]> granicus.if.org Git - python/commitdiff
Added example to enum docs show access to name and value attributes of enum members.
authorEthan Furman <ethan@stoneleaf.us>
Fri, 28 Jun 2013 21:02:34 +0000 (14:02 -0700)
committerEthan Furman <ethan@stoneleaf.us>
Fri, 28 Jun 2013 21:02:34 +0000 (14:02 -0700)
Doc/library/enum.rst

index ae0498ca30e34f02669b33f2898c29ad4a7bbb02..89791819f6e8575c1e11e598b6ab58054e26d039 100644 (file)
@@ -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
 -----------------------------------