When to use assert

Mark Lawrence breamoreboy at yahoo.co.uk
Mon Nov 18 05:02:39 EST 2013


On 18/11/2013 09:50, Oscar Benjamin wrote:
> 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
>

If I used something that often I'd either cut and paste it or have a key 
combination set up to insert it automatically.  Or get my man to type it 
up for me :)

-- 
Python is the second best programming language in the world.
But the best has yet to be invented.  Christian Tismer

Mark Lawrence




More information about the Python-list mailing list