When to use assert

Oscar Benjamin oscar.j.benjamin at gmail.com
Mon Nov 18 04:50:11 EST 2013


On 17 November 2013 13:33, Roy Smith <roy at panix.com> wrote:
>
> So, I stick "assert 0" in the code an re-run the program to see if I get
> an AssertionError.  If I do, then I know the code is being run.  If I
> don't then I know it's not.  Either way, I know more about what's going
> on than I did before.  Once I know what's going on, I remove the assert.

If the program is invoked from a terminal I would probably go with
'import pdb; pdb.set_trace()' rather than 'assert 0'. Then you can
check much more than whether or not the code is being executed. It's a
bit more to type but I type it so often that I can now type it *really
fast*.


Oscar



More information about the Python-list mailing list