Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I debug a Python program (I am coming from a Ruby on Rails/JavaScript background)? [closed]

I make web applications using Ruby on Rails as my backend. I use React and Flux on the frontend, which is JavaScript. I can fully use the debugging tools I need. I simply add the line of code "debugger" anywhere in my app, so that execution stops there. I use byebug gem in Rails. When the "debugger" line of code is executed on backend code, the debugging happens on the command line; when it happens in JavaScript code, the debugging happens in Chrome Dev Tools. In other words, I can work very quickly to debug.

What is the equivalent convenient debugging tool in Python? In other words, what should a person who can already program in general, and just wants to rapidly be able to debug in Python use? I am using Atom editor (like I use when I am making a web app).

like image 810
evianpring Avatar asked Mar 14 '16 15:03

evianpring


1 Answers

You can use pdb

To add a breakpoint, insert:

import pdb; pdb.set_trace()

where you want to stop.

NB: Since python 3.7, you just can do

breakpoint()

In the debugger mode you can use the following commands.

like image 130
loutre Avatar answered Oct 11 '22 14:10

loutre