• Home
  • weblog
  • 2014
  • 03
  • 31
  • Print(reinout) for debugging

Print(reinout) for debugging¶

Tags: python

Quite some colleagues use my name to raise an error. It is a trick I learned them :-)

There are a large number of debugging tips and tricks. import pdb; print statements; a full-blown IDE with an interactive debugger; logging; etc.

Often the simplest and most useful thing to check is to first verify that you’re looking in the right place at all. Why? Well, you might be working on the right python file, but are you really sure that your web app isn’t using a previously installed package instead of your checked out developer version, for instance?

Or you work on some method, but another class overrides the method you’re debugging.

In cases like this I often add a print(reinout) statement somewhere in the function. That’s not a typo. It definitively should not be print("reinout"). The latter only prints reinout, the first prints:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'reinout' is not defined

Much easier to spot. Makes it obvious that at least you’re looking in the right spot!

vanrees.org logo

Reinout van Rees

  • Weblog
  • Over mij (NL)
  • About me (EN)
  • Ligfiets (NL)
  • Klussen en doe-het-zelven (NL)
  • Eifelburgenbahn (model railway)
  • Videos
  • Preken (NL)
  • PhD (EN)

Weblog feeds

Most of my website content is in my weblog. You can keep up to date by subscribing to the automatic feeds (for instance with Newsblur):

  • Atom feed of my full weblog
  • Atom feed, filtered to just the Python/Django content.
Contact: reinout@vanrees.org
Copyright © Reinout van Rees (unless otherwise indicated)
Text: CC BY-NC-SA 4.0, Images/video: CC BY-SA 4.0