Debug

After watching, Clayton Parker - So you think you can PDB? - PyCon 2015, I have started using pdbpp.

I think you might like it…

_images/pdbpp.png

Add the following to requirements/local.txt:

setuptools_scm
# must come after ``setuptools_scm``
pdbpp

Note

If you get a setuptools_scm error when installing pdbpp, then manually install setuptools_scm i.e. pip install setuptools_scm

Note

You might want to remove ipdb (if you have been using it). ipython still appears to work in the Django shell.

Download a nice looking .pdbrc.py file and copy to your home folder. I downloaded this one: https://github.com/claytron/dotfiles/blob/master/.pdbrc.py

To debug, add the following to the line of your code where you want the breakpoint:

import pdb; pdb.set_trace()

prettyprinter

pip install prettyprinter
import prettyprinter
prettyprinter.prettyprinter.install_extras(["attrs"])
prettyprinter.pprint(data)

Timing

To measure the time taken to do something (or other):

from timeit import default_timer as timer

print(">>>")
start = timer()

# do something

end = timer()
# Time in seconds, e.g. 5.38091952400282
print("<<< {}".format(end - start))