[Python-Dev] PEP 435 -- Adding an Enum type to the Python standard library
ethan at stoneleaf.us
Sat Apr 27 04:09:15 CEST 2013
On 04/26/2013 06:37 PM, Greg Ewing wrote:
> Eli Bendersky wrote:
>> There's a conceptual difference between a value of an enumeration and a collection of such values.
> Not if you think of an enum as a type and a type as
> defining a set of values. From that point of view, the
> enum itself is already a collection of values, and
> introducing another object is creating an artificial
I agree (FWIW ;).
It seems to me that the closest existing Python data type is bool.
bool is a type and has exactly two members, which are static/singleton/only created once.
Enum is a metatype which we use to create a type with a fixed number of members which are static/singleton/only created
The salient differences:
with Enum we name the type and the members
with Enum the members are also attributes of the type
As a concrete example, consider:
SUNDAY = 1
MONDAY = 2
TUESDAY = 3
WEDNESDAY = 4
THURSDAY = 5
FRIDAY = 6
SATURDAY = 7
If we follow bool's example, then like True and False are of type(bool), TUESDAY should be of type(WeekDay).
More information about the Python-Dev