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
distinction.
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
once.
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:
class WeekDay(Enum):
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).
--
~Ethan~
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe:
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com