This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2008年03月28日 11:05 by calvin, last changed 2022年04月11日 14:56 by admin. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| 0001-Add-enum-example-for-named-tuples.patch | calvin, 2008年03月28日 11:05 | |||
| Messages (5) | |||
|---|---|---|---|
| msg64627 - (view) | Author: Bastian Kleineidam (calvin) | Date: 2008年03月28日 11:05 | |
Named tuples can also be used to emulate enum datatypes. The patch adds an example to the documentation. |
|||
| msg64629 - (view) | Author: Bastian Kleineidam (calvin) | Date: 2008年03月28日 11:22 | |
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. |
|||
| msg64635 - (view) | Author: Georg Brandl (georg.brandl) * (Python committer) | Date: 2008年03月28日 12:58 | |
Fixed example (a * was missing) and committed as r62007. Thanks! |
|||
| msg64636 - (view) | Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) | Date: 2008年03月28日 13:05 | |
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)))
|
|||
| msg64689 - (view) | Author: Raymond Hettinger (rhettinger) * (Python committer) | Date: 2008年03月29日 09:58 | |
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 faster and still allows prefixing using the module name (for example, re.MULTILINE). |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:56:32 | admin | set | github: 46754 |
| 2008年03月29日 09:58:02 | rhettinger | set | resolution: accepted -> rejected messages: + msg64689 |
| 2008年03月28日 13:05:27 | amaury.forgeotdarc | set | nosy:
+ amaury.forgeotdarc, rhettinger messages: + msg64636 |
| 2008年03月28日 12:58:44 | georg.brandl | set | status: open -> closed resolution: accepted messages: + msg64635 |
| 2008年03月28日 11:22:57 | calvin | set | messages: + msg64629 |
| 2008年03月28日 11:05:19 | calvin | create | |