assert 0, "foo" vs. assert(0, "foo")
Scott David Daniels
Scott.Daniels at Acm.Org
Wed Feb 23 09:44:43 EST 2005
Thomas Guettler wrote:
> Hi,
>
> Python 2.3.3 (#1, Feb 5 2005, 16:22:10) [GCC 3.3.3 (SuSE Linux)] on linux2
>
>>>>assert 0, "foo"
>
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> AssertionError: foo
>
>>>>assert(0, "foo")
>>>>
>
>
> If you use parenthesis for the assert statement, it never
> raises an exception.
>
> Up to now I raised strings, but since this is deprecated,
> I switched to use the second argument for the assert
> statement.
>
> Is it possible to change future python versions, that
> assert accept parenthesis?
You are confusing assert with raise.
assert test, text
behaves like:
if __debug__ and test:
raise AssertionError, text
As far as raise goes, where you have been writing:
raise "some complaint"
you could simply use:
raise ValueError, "some complaint"
or:
raise ValueError("some complaint")
--Scott David Daniels
Scott.Daniels at Acm.Org
More information about the Python-list
mailing list