Falsey Enums

Steve D'Aprano steve+python at pearwood.info
Fri Jul 28 06:28:29 EDT 2017


On 2017年7月28日 05:52 pm, Ethan Furman wrote:
> class X(Enum):
> Falsey = 0
> Truthy = 1
> Fakey = 2
> def __bool__(self):
> return bool(self.value)

Thanks Ethan.
Like Ben, I'm surprised that's not the default behaviour.
-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.


More information about the Python-list mailing list

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