Net-informations.com
SiteMap  | About    

Debugging in Python

Python has a debugger , which is available as a module called pdb . It supports setting conditional breakpoints , stepping through the source code one line at a time, stack inspection, and more.

Insert pdb.set_trace() anywhere and it will function as a breakpoint . When you execute the script by python test.py, you will in the debug mode.

Some useful debugging commands:

  1. b: set a breakpoint
  2. c: continue debugging until you hit a breakpoint
  3. s: step through the code
  4. n: to go to next line of code
  5. l: list source code for the current file
  6. u: navigate up a stack frame
  7. d: navigate down a stack frame
  8. p: to print the value of an expression in the current context
  9. q: quit

Running from command line of python interpreter.

If you don't like spending time in debuggers, you can dump execution trace and analyse it later.









net-informations.com (C) 2017    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.