Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
3fe70b4a
Commit
3fe70b4a
authored
Jun 28, 2013
by
Ethan Furman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added example to enum docs show access to name and value attributes of enum members.
parent
cf873c69
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
2 deletions
+10
-2
Doc/library/enum.rst
Doc/library/enum.rst
+10
-2
No files found.
Doc/library/enum.rst
View file @
3fe70b4a
...
...
@@ -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
-----------------------------------
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment