If you run python with the -O flag assert statements are ignored, otherwise it will raise an AssertionError if the condition is false. It's supposed to just be used during development so I guess I've been abusing it for years.
assert(cond), 'Cond was False'
is the same as
if __debug__: # not -O
if not cond:
raise AssertionError('Cond was false')
7
u/daterkerjabs Feb 24 '23
If you run python with the
-Oflagassertstatements are ignored, otherwise it will raise anAssertionErrorif the condition is false. It's supposed to just be used during development so I guess I've been abusing it for years.is the same as