Videos
Factsheet
/ 2 February 2026; 45 days ago (2 February 2026)
/ 2 February 2026; 45 days ago (2 February 2026)
Yes! There's a Python debugger called pdb just for doing that!
You can launch a Python program through pdb via python -m pdb myscript.py.
There are a few commands you can then issue, which are documented on the pdb page.
Some useful ones to remember are:
b: set a breakpointc: continue debugging until you hit a breakpoints: step through the coden: to go to next line of codel: list source code for the current file (default: 11 lines including the line being executed)u: navigate up a stack framed: navigate down a stack framep: to print the value of an expression in the current context
If you don't want to use a command line debugger, some IDEs like Pydev, Wing IDE or PyCharm have a GUI debugger. Wing and PyCharm are commercial products, but Wing has a free "Personal" edition, and PyCharm has a free community edition.
By using Python Interactive Debugger 'pdb'
First step is to make the Python interpreter enter into the debugging mode.
A. From the Command Line
Most straight forward way, running from command line, of python interpreter
$ python -m pdb scriptName.py
> .../pdb_script.py(7)<module>()
-> """
(Pdb)
B. Within the Interpreter
While developing early versions of modules and to experiment it more iteratively.
$ python
Python 2.7 (r27:82508, Jul 3 2010, 21:12:11)
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pdb_script
>>> import pdb
>>> pdb.run('pdb_script.MyObj(5).go()')
> <string>(1)<module>()
(Pdb)
C. From Within Your Program
For a big project and long-running module, can start the debugging from inside the program using
import pdb and set_trace()
like this:
#!/usr/bin/env python
# encoding: utf-8
#
import pdb
class MyObj(object):
count = 5
def __init__(self):
self.count= 9
def go(self):
for i in range(self.count):
pdb.set_trace()
print i
return
if __name__ == '__main__':
MyObj(5).go()
Step-by-Step debugging to go into more internal
Execute the next statement… with “n” (next)
Repeating the last debugging command… with ENTER
Quitting it all… with “q” (quit)
Printing the value of variables… with “p” (print)
a)
p aTurning off the (Pdb) prompt… with “c” (continue)
Seeing where you are… with “l” (list)
Stepping into subroutines… with “s” (step into)
Continuing… but just to the end of the current subroutine… with “r” (return)
Assign a new value
a)
!b = "B"Set a breakpoint
a)
break linenumberb)
break functionnamec)
break filename:linenumberTemporary breakpoint
a)
tbreak linenumberConditional breakpoint
a)
break linenumber, condition
Note: All these commands should be executed from pdb
For in-depth knowledge, refer:
https://pymotw.com/2/pdb/
https://pythonconquerstheuniverse.wordpress.com/2009/09/10/debugging-in-python/
Hi all! I stumbled across this subreddit a few months ago, and was impressed with the scene here. Y'all seem more mature and purely want to learn/share knowledge, unlike other places that seem to get clogged up with "here's my homework do it for me" type requests. I made a mental note to come back when I got some projects of mine into stable/usable states.
I'm a programmer (big generalization) by day, and am constantly helping coworkers/friends/family/etc with programming and computer questions and concepts. Long story short, I got fed up with the available online code-sharing/debugging tools, and wrote my own. (I was also looking for an excuse to use some new technologies).
I'm rather proud of the work I did on them. Anyways, just wanted to share them and let y'all know that there's some new (and IMO better, but I'm pretty biased) tools out there for sharing/debugging code samples and helping others learn.
These are my two sites that are finally at version 1.0 (maybe still a bit beta though)
-
dbgr.cc - online code debugger/sharer - only python (my favorite) is currently supported for debugging - I'll be implementing other languages soon-ish
-
noobcoderz.com - tutorial site that uses the online debugger for code examples. I only have a general programming tutorial section and a bit of a python section up right now.
I see dbgr.cc being most useful for code sharing/debugging for r/learnpython though.
I hope they're as useful as I've imagined them to be. If not, oh well, they were fun to make.
Thanks for reading!
-n