[Python-Dev] constant/enum type in stdlib (original) (raw)
Steven D'Aprano steve at pearwood.info
Tue Nov 23 22:30:37 CET 2010
- Previous message: [Python-Dev] constant/enum type in stdlib
- Next message: [Python-Dev] constant/enum type in stdlib
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Antoine Pitrou wrote:
Python already has an enumeration capability. It's called range(). There's nothing else that C enums have. AFAICT, neither do enums in other mainstream languages (assuming they even exist; I don't remember Perl, PHP or Javascript having anything like that, but perhaps I'm mistaken).
In Pascal, enumerations are a type, and the value of the named values are an implementation detail. E.g. one would define an enumerated type:
type flavour = (sweet, salty, sour, bitter, umame); var x: flavour;
and then you would write something like:
x := sour;
Notice that the constants sweet etc. aren't explicitly predefined, since they're purely internal details and the compiler is allowed to number them any way it likes. In Python, we would need stronger guarantees about the values chosen, so that they could be exposed to external modules, pickled, etc.
But that doesn't mean we should be forced to specify the values ourselves.
-- Steven
- Previous message: [Python-Dev] constant/enum type in stdlib
- Next message: [Python-Dev] constant/enum type in stdlib
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]