PeetRonics' blog

All can be true!

Wed 20 November 2019 - read time: 2 min.

What I Have Learned Today - #016

  

Python debugging with PDB

Lazy man’s debugging

Sure I’m not the only one out, but I’m still the kind of person that does debugging by dotting the code with print() statements. And with the release of Python 3.8 and the f-string support it seems that they want me to keep to stick to that habit:

>>> user = "eric_idle"
>>> member_since = date(1975, 7, 31)
>>> f"{user=} {member_since=}"
user="eric_idle" member_since=datetime.date(1975, 7, 31)

That’s a nice addition.

A better alternative

At my work I’m not making a secret of my approach to debugging and a colleague once pointed out the debug capabilities of the IDE. Tried that but never caught on with me. So yes, I still have the ubiquitous print statements everywhere, which I always forget to remove.

Today I was joking about my debug super powers again and then another colleague pointed out PDB; a Python debugger that can be used from the command line. I found a handy tutorial from Real Python which I followed which got me started.

Still a lot to learn on this, but practice makes perfect. So I will stick with this. So far so good.

This post is part of a series of articles about “What I Have Learned Today”; acknowledging every day the thing I have learned. Feel free to read the other posts. all opinions in this article are my own and not necessarily represent the views of my employer.