Paul Rubin wrote:
Invalid input data is not considered impossible and doesn't imply a
broken program, so assert statements are not the appropriate way to
check for it. I like to use a function like
def check(condition, msg="data error"):
if not condition: raise ValueError, msg
...
check (x >= 0, "invalid x") # raises ValueError if x is negative
y = sqrt(x)
And I curse such uses, since I don't get to see the troublesome value,
or why it is troublesome. In the above case, y = sqrt(x) at least
raises ValueError('math domain error'), which is more information than
you are providing.
How about:
...
if x >= 0: raise ValueError('x = %r not allowed (negative)?' % x)
...
--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list