Assert statements in python 3.1

Mark Dickinson dickinsm at gmail.com
Fri Aug 20 03:27:14 EDT 2010


On Aug 20, 6:13 am, genxtech <jrmy.l... at gmail.com> wrote:
> This is more of a curiosity question then anything else...  I was just
> wondering why in version 3 of python assertions weren't converted to
> use parenthesis, since print was.
>
> I am just asking because it seems the following line of code would
> seem more readable as a function:
>    assert 2 + 2 == 5, "Only for very large values of 2."

Well, part of the idea of asserts is that when you're running with
optimizations turned on (python -O), asserts should be disabled.  But
if assert were a normal function then in

    assert(expensive_check)

the argument expensive_check would be evaluated both with 'python' and
with 'python -O'.

--
Mark



More information about the Python-list mailing list