When to use assert

Tim Chase python.list at tim.thechases.com
Mon Nov 18 06:44:58 EST 2013


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

I do this so much that on my main development machines, I have a line
in my vimrc file

  nnoremap <leader>p oimport pdb; pdb.set_trace()<esc>
  nnoremap <leader>P Oimport pdb; pdb.set_trace()<esc>

which maps the the leader key (defaults to "\") followed by p/P to
insert the pdb line below/above the current line.  Saves bunches of
time & hassle.  I'm sure it's equally easy in other quality editors.

-tkc






More information about the Python-list mailing list