> "Thomas Guettler" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
> Hi,

> Python 2.3.3 (#1, Feb  5 2005, 16:22:10) [GCC 3.3.3 (SuSE Linux)] on
linux2
> >>> assert 0, "foo"

Assert that 0 is true.  If that fails, raise AssertionError("foo").

> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
> AssertionError: foo
> >>> assert(0, "foo")

Assert that the tuple (0, "foo") is true.  Non-empty tuples are always true.

> >>>
>
> 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?

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?

>  Thomas

> -- 
> Thomas Güttler, http://www.thomas-guettler.de/



-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to