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
Stormwallker
Tue Sep 15 15:52:32 2026
from
Hinckley, Leicestershire
via
Telnet
Rixter
Tue Sep 15 12:01:35 2026
from
Madison, Nc
via
Telnet
Bob Worm
Tue Sep 15 11:25:46 2026
from
Wales, Uk
via
Telnet
Andrew Andrew
Tue Sep 15 02:46:28 2026
from
Chicago, Il
via
Telnet
Netmages
Tue Sep 15 01:13:15 2026
from
Santiago, Chile
via
SSH
Rixter
Tue Sep 15 00:01:34 2026
from
Madison, Nc
via
Telnet
Rixter
Mon Sep 14 12:01:34 2026
from
Madison, Nc
via
Telnet
Bob Worm
Mon Sep 14 08:34:31 2026
from
Wales, Uk
via
Telnet
System Info
Sysop:
Keyop
Location:
Huddersfield, West Yorkshire, UK
Users:
766
Nodes:
16 (
1
/
15
)
Uptime:
07:16:30
Calls:
12,762
Calls today:
6
Files:
15,362
Messages:
6,557,053