[Python-Dev] PEP 435 -- Adding an Enum type to the Python standard library (original) (raw)

Philip Jenvey pjenvey at underboss.org
Tue Apr 23 22:20:48 CEST 2013


On Apr 23, 2013, at 8:11 AM, Guido van Rossum wrote:

I gotta say, I'm with Antoine here. It's pretty natural (also coming from other languages) to assume that the class used to define the enums is also the type of the enum values. Certainly this is how it works in Java and C++, and I would say it's the same in Pascal and probably most other languages.

Furthermore, you could define methods/fields on enum values, like Java's enums.

E.g.: Errno.EBADF.strerror() -> 'Bad file descriptor'

Easily adapt to additional fields:

class Protocol(Enum):

HOPOPT = 0, "IPv6 Hop-by-Hop Option" ICMP = 1, "Internet Control Message" IGMP = 2, "Internet Group Management"

@property def value(self): return self._value[0]

@property def description(self): return self._value[1]

-- Philip Jenvey



More information about the Python-Dev mailing list