Enum class

Peter Otten __peter__ at web.de
Thu Oct 15 08:29:48 EDT 2015


Joseph L. Casale wrote:
> Is it possible to override __contains__ from the meta class in the derived
> class with the Enum type?

>>> import enum
>>> class M(enum.EnumMeta):
... def __contains__(self, value):
... print("checking", value)
... return super().__contains__(value)
... 
>>> class Colors(enum.Enum, metaclass=M):
... red = 1
... green = 2
... blue = 3
... 
>>> Colors.red in Colors
checking Colors.red
True
Is that what you're asking for? If not can you give an example?


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /