Pop-Up Thingie
Sidebar
>>> Magnum BBS <<<
Home
Forum
Files
Dark
Log in
Username
Password
Sidebar
Forum
Usenet
COMP.LANG.PYTHON
Non int Boolean
From
Weatherby,Gerard
@21:1/5 to
All
on Sat Jan 28 19:44:03 2023
If someone really really wants a non-int Boolean, it is easy to implement. 5 or 6 lines, depending on whether you count the import statement:
from enum import Enum
class MyBool(Enum):
TRUE = 42
FALSE = 54
def __bool__(self):
return self == MyBool.TRUE
#
# testing
#
mytrue = MyBool.TRUE
try:
print(int(mytrue)) #this fails
except TypeError as te:
print(te)
asbool = bool(mytrue)
if mytrue:
print("yep")
myfalse = MyBool.FALSE
if myfalse:
print("nope")
---
I would never use such a thing, and I would be annoyed if I can across code that did. As has been said (beaten to death?) Python has an existing well-understood boolean type.
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)
Who's Online
Recent Visitors
Fred Blogs
Mon Sep 15 00:03:12 2025
from
Uk
via
SSH
Plume
Sun Sep 14 09:34:52 2025
from
Uk
via
Raw
Gretchiie
Sun Sep 14 06:07:30 2025
from
Derry, Nh
via
Telnet
Thlc
Sat Sep 13 17:11:34 2025
from
Rognac, France
via
Telnet
Thlc
Sat Sep 13 17:04:03 2025
from
Rognac, France
via
Telnet
Thlc
Sat Sep 13 16:32:19 2025
from
Rognac, France
via
SSH
Thlc
Sat Sep 13 15:41:11 2025
from
Rognac, France
via
SSH
Thlc
Sat Sep 13 07:56:03 2025
from
Rognac, France
via
SSH
System Info
Sysop:
Keyop
Location:
Huddersfield, West Yorkshire, UK
Users:
546
Nodes:
16 (
2
/
14
)
Uptime:
05:54:51
Calls:
10,386
Calls today:
1
Files:
14,058
Messages:
6,416,633