[Python-ideas] Enums

Ben Finney ben+python at benfinney.id.au
Thu Jul 28 01:52:12 CEST 2011


Ethan Furman <ethan at stoneleaf.us> writes:

> In most cases I agree, but there can be exceptions.  Consider:
>
> class StoveTemps(Enum):
>     off = 0
>     low = 15
>     medium = 50
>     high = 85

That doesn't seem like an appropriate use of an enumerated type, then.
For an enumerated type, the integers are arbitrary and the important
part is the name.

If the integer values actually *mean* something, then let's have them as
name bindings to those values.

> In such a case I see no issues with
>
>     if temp < StoveTemps.medium:
>         what_ever()

-- 
 \               “Anger makes dull men witty, but it keeps them poor.” |
  `\                                                  —Elizabeth Tudor |
_o__)                                                                  |
Ben Finney




More information about the Python-ideas mailing list