Raymond Hettinger [EMAIL PROTECTED] added the comment:
Thanks for asking. This should not go into the collections module.
The concept makes more sense in statically compiled languages. In
Python, we typically write something like RED, ORANGE, YELLOW = range
(3) at the module level. That is
New submission from Wummel [EMAIL PROTECTED]:
Named tuples can also be used to emulate enum datatypes. The patch adds
an example to the documentation.
--
assignee: georg.brandl
components: Documentation
files: 0001-Add-enum-example-for-named-tuples.patch
keywords: patch
messages: 64627
Wummel [EMAIL PROTECTED] added the comment:
The motivation for this patch is that documenting a single function
adding enum-like capabilities would hopefully eliminate the numerous
enum recipies already out there, each handling things a little different.
__
Georg Brandl [EMAIL PROTECTED] added the comment:
Fixed example (a * was missing) and committed as r62007. Thanks!
--
resolution: - accepted
status: open - closed
__
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue2502
Amaury Forgeot d'Arc [EMAIL PROTECTED] added the comment:
Raymond, is this kind of recipes worth adding to the 'collections' module?
Maybe with the following form:
def enum(*valuenames):
return namedtuple('Enum', valuenames)(*range(len(valuenames)))
--
nosy: +amaury.forgeotdarc,