Am I stupid or is 'assert' broken in Python 2.5??
Marc 'BlackJack' Rintsch
bj_666 at gmx.net
Wed Dec 6 09:42:16 EST 2006
In <1165415689.347819.129680 at 73g2000cwn.googlegroups.com>, antred wrote:
> Run the following code in your Python interpreter:
>
> myString = None
>
> assert( myString, 'The string is either empty or set to the None type!'
> )
> assert( myString )
>
>
>
> You'll notice that the first assert doesn't do anything, whereas the
> second assert correctly recognizes that myString does not evaluate to
> true. That doesn't seem right. Surely Python should have raised an
> assertion error on the first assert statement, right??
``assert`` is a statement, not a function. And non-empty tuples are "true":
assert (False, 'boink')
This is equivalent to ``assert True``.
Ciao,
Marc 'BlackJack' Rintsch
More information about the Python-list
mailing list