On 7/28/17, Steve D'Aprano wrote:
> On Fri, 28 Jul 2017 05:52 pm, Ethan Furman wrote:
>
>> class X(Enum):
>> Falsey = 0
>> Truthy = 1
>> Fakey = 2
>> def __bool__(self):
>> return bool(self.value)
>
> Thanks Ethan.
BTW bool at enum seems to be expensive:
%timeit 7 if
On 07/28/2017 01:13 AM, Ben Finney wrote:
Ethan Furman writes:
class X(Enum):
Falsey = 0
Truthy = 1
Fakey = 2
def __bool__(self):
return bool(self.value)
I am surprised this is not already the behaviour of an Enum class,
without overriding the ‘__bool__’ method.
On Fri, Jul 28, 2017 at 8:28 PM, Steve D'Aprano
wrote:
> On Fri, 28 Jul 2017 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'
On Fri, 28 Jul 2017 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, “thing
On Friday, July 28, 2017 at 1:45:46 PM UTC+5:30, Ben Finney wrote:
> Ethan Furman writes:
>
> > class X(Enum):
> > Falsey = 0
> > Truthy = 1
> > Fakey = 2
> > def __bool__(self):
> > return bool(self.value)
>
> I am surprised this is not already the behaviour of an Enum c
Ethan Furman writes:
> class X(Enum):
> Falsey = 0
> Truthy = 1
> Fakey = 2
> def __bool__(self):
> return bool(self.value)
I am surprised this is not already the behaviour of an Enum class,
without overriding the ‘__bool__’ method.
What would be a good reason not to hav
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
Dan Sommers writes:
> def __bool__(self):
> return False if self == X.Falsey else True
return self != X.Falsey
--
https://mail.python.org/mailman/listinfo/python-list
On Fri, 28 Jul 2017 12:15:20 +1000, 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?
Add the following to your en
Isn't dunder-bool what you want?
(dunder-nonzero in python2)
Dunno if special caveats for Enums
PS sorry for phone-post -- I've broken my leg
--
https://mail.python.org/mailman/listinfo/python-list
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?
--
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.
11 matches
Mail list logo