-
Is there a performance or code maintenance issue with using
assertas part of the standard code instead of using it just for debugging purposes?Is
assert x >= 0, 'x is less than zero'better or worse than
if x < 0: raise Exception('x is less than zero') -
Also, is there any way to set a business rule like
if x < 0 raise errorthat is always checked without thetry/except/finallyso, if at anytime throughout the codexis less than 0 an error is raised, like if you setassert x < 0at the start of a function, anywhere within the function wherexbecomes less then 0 an exception is raised?
Is there a performance or code maintenance issue with using assert as part of
Share
To be able to automatically throw an error when x become less than zero throughout the function. You can use class descriptors. Here is an example: