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
Krenn
Sun Jun 7 10:02:33 2026
from
Sydney, Nsw
via
Telnet
Spearb0y
Sun Jun 7 07:41:05 2026
from
Massachusetts
via
SSH
Krenn
Sun Jun 7 03:07:26 2026
from
Sydney, Nsw
via
Telnet
Krenn
Sun Jun 7 01:30:12 2026
from
Sydney, Nsw
via
Telnet
Centurion
Sat Jun 6 23:27:30 2026
from
Berea, Ohio
via
Telnet
Ab Cadd
Sat Jun 6 15:42:53 2026
from
Sheboygan, Wi
via
Telnet
Centurion
Sat Jun 6 15:32:28 2026
from
Berea, Ohio
via
Telnet
Krenn
Sat Jun 6 11:38:56 2026
from
Sydney, Nsw
via
Telnet
System Info
Sysop:
Keyop
Location:
Huddersfield, West Yorkshire, UK
Users:
715
Nodes:
16 (
0
/
16
)
Uptime:
167:56:16
Calls:
12,096
Calls today:
4
Files:
15,003
Messages:
6,517,819