[Python-ideas] another enum implementation
Ethan Furman
ethan at stoneleaf.us
Wed Feb 13 07:38:11 CET 2013
On 02/12/2013 10:18 PM, Senthil Kumaran wrote:
> Two comments.
>
> 1. When it is fully generalized, is type is the way to to specify the
> type of enums? Or there will be helper functions or classes that can
> specify the type of enum one desires.
Creating enums with the class method is so easy I don't see myself
spending time on helper functions.
I'll have to think some more about using
type = 'unique'
vs.
class Geometry(UniqueEnum)
although I feel myself leaning towards the UniqueEnum style.
> 2. Personally, I have resorted to using namedtuples for enum like
> behavior. How would this class benefit me? Any edification would be
> helpful.
namedtuples are designed to have many instances with different values in
the same slots; the Enum class is a singleton, and its instances are the
values.
The Enum class' instances are derived from either int or str, so they
can be an easy drop-in replacement to API's that currently expect ints
or strs.
Better repr()'s. :)
--
~Ethan~
P.S.
Definitely read the other thread, and no worries.
More information about the Python-ideas
mailing list