Falsey Enums

Ethan Furman ethan at stoneleaf.us
Fri Jul 28 03:52:23 EDT 2017


On 07/27/2017 07:15 PM, Steve D'Aprano wrote:
> I has some Enums:
>> from enum import Enum
> class X(Enum):
> Falsey = 0
> Truthy = 1
> Fakey = 2
>>> and I want bool(X.Falsey) to be False, and the others to be True. What should I
> do?

class X(Enum):
 Falsey = 0
 Truthy = 1
 Fakey = 2
 def __bool__(self):
 return bool(self.value)
--
~Ethan~


More information about the Python-list mailing list

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