Wrangling snakes like a pro with PuDB

By Sambhav Kothari

Elevator Pitch

Ever find yourself using print statements to figure out a pesky off-by-one error? Tired of commenting and un-commenting lines as you rip your hair out only to discover a minor typo? There’s no need to manually debug your code! Learn how to debug your Python scripts like a pro – in under 30 mins!

Description

Motivation

def my_totally_awesome_function(variable_a):
    print("-----------------")
    # Using f-strings coz python3.7 is the future bro!!!
    print(f"A: {variable_a}")
    variable_b = do_something(variable_a)
    print(f"B: {variable_b}")
    # print("Why me??????????")
    # print("can I haz more print statements")
    return variable_b

If the above brings back horrible memories of your eyes fixated on the screen at 2 AM trying to figure out why your code won’t do exactly what you want it to do, then this is just the right talk for you.

To be honest, Python makes “debugging” your code using print statements very easy. So easy that I’ve even had friends tell me - “Why bother a debugger with an interpreted language like Python, when you can just slap some prints over the code and get on with it”.

Why should I spend 30 mins of my life learning about Python debugging when I can just “print” my way out of it?

For starters, using print can be time consuming, especially when you don’t know what you are looking for or where to look for it. Next, debugging is often an iterative process. You make one small change, observe the code behavior, and iterate further. This is where Python debuggers shine. They are special tools that let you pause code-execution, freely inspect or modify your run-time variables, and step through your code line-by-line. They make debugging your code simple and extremely convenient (hence their name). PuDB takes things a step further and gives you a full-blown UI inside your terminal, so you can hack away at your scripts even when you are logged in to a remote shell.

Takeaways

In this talk, I will give an introduction to debugging in Python using PuDB. I will go through a demonstration showcasing PuDB in action, as we debug a buggy Python script. During this live demonstration, I will also provide some tips and tricks to make the debugging experience smoother, including how to take advantage of new Python features – like the builtin breakpoint – that seamlessly integrate debugging in your Python code. By the end of the talk, attendees will have a basic grasp of how to use Python debuggers and will be able to debug their code more effectively.