> "Thomas Guettler" <guettli@thomas-guettler.de> wrote in message[color=blue]
> news:pan.2005.02.23.09.57.43.578480@thomas-guettler.de...
> Hi,[/color]
[color=blue]
> Python 2.3.3 (#1, Feb 5 2005, 16:22:10) [GCC 3.3.3 (SuSE Linux)] on[/color]
linux2[color=blue][color=green][color=darkred]
> >>> assert 0, "foo"[/color][/color][/color]
Assert that 0 is true. If that fails, raise AssertionError("foo").
[color=blue]
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> AssertionError: foo[color=green][color=darkred]
> >>> assert(0, "foo")[/color][/color][/color]
Assert that the tuple (0, "foo") is true. Non-empty tuples are always true.
[color=blue][color=green][color=darkred]
> >>>[/color][/color]
>
> If you use parenthesis for the assert statement, it never
> raises an exception.[/color]
[color=blue]
> Up to now I raised strings, but since this is deprecated,
> I switched to use the second argument for the assert
> statement.[/color]
[color=blue]
> Is it possible to change future python versions, that
> assert accept parenthesis?[/color]
As shown above, it does, but it doesn't do quite what you expected. For
further enlightenment, try the following and think through why each one
gives the results it does:
assert (), 'spam'
assert [], 'eggs'
assert {}, 'spam and eggs'
assert (0,), 'spam, spam, and eggs'
assert (0, "foo"), 'spam, spam, eggs, and spam'
assert 0, "foo", 'shrubbery'
The last will give a syntax error. Can you spot why?
[color=blue]
> Thomas[/color]
[color=blue]
> --
> Thomas Güttler,
http://www.thomas-guettler.de/[/color]