r/pythontips • • Mar 24 '21

Python3_Specific How to debug in Python?

Please share some tips about the title.

32 Upvotes

38 comments sorted by

View all comments

6

u/miamiredo Mar 25 '21

Really surprised no one mentioned:

import pdb

pdb.set_trace()

I put that anywhere I want to inspect what is going on and run the script! Then you can see what variables are at that point and also go through the code line by line!

1

u/zaxswyre Mar 26 '21

New in version 3.7: The built-in

breakpoint()

, when called with defaults, can be used instead of

import pdb; pdb.set_trace()

.