Enum class
Joseph L. Casale
jcasale at activenetwerx.com
Thu Oct 15 21:52:05 EDT 2015
> Like that?
>
> >>> class M2(enum.EnumMeta):
>... def __contains__(self, value):
>... print(value, "? never", sep="")
>... return False
>...
> >>> Colors.__class__
> <class '__main__.M'>
> >>> Colors.red in Colors
> checking Colors.red
> True
> >>> Colors.__class__ = M2
> >>> Colors.red in Colors
> Colors.red? never
> False
Hah, that's pretty clever:) I was thinking without creating my own
meta class, but modifying the Colors class. It's not really a big deal
all the solutions here are more than adequate!
Thanks a lot Peter,
jlc
More information about the Python-list
mailing list