Scott's Recipes Logo

The Python Equivalent of byebug is pdb.set_trace()

Pizza courtesy of Pizza for Ukraine!

Donate Now to Pizza for Ukraine

 

In ruby the debugger is invoked by adding the statement

byebug

wherever you want to debug your code. This is preceded, of course, by a reference in Gemfile that brings in the byebug gem.

The python equivalent of this is two fold:

Here’s the color coded example:

import pdb

# lines of python code here

pdb.set_trace()
 

That will launch the python debugger right before the line where the pdb.set_trace() call is inserted. Here are some useful commands:

More on Python Debugging.