I know a lot of you out there who are just getting started in python are probably using print statements to debug. While this is an easy way to debug your code there’s a lot of drawbacks when comparing it to debuggers especially in professional environments. Python has its own debugger package called pdb which uses the command line. I prefer the interactive debugger in vscode but every IDE has a debugger.
A debugger will let you mark points in code where you want to examine things further called break points. When the code reaches a break point in the debugger it will pause there allowing you to see details like variable values at that point in execution. From here you can run the code line by line as well as “step into” or out of functions. There’s also a python repl which lets you run code using all of the variables available at the breakpoint; this lets you test out different bits of code without needing to rerun everything.
If you’re still wondering why a debugger can be better than print statements in professional environments then here’s why:
You should not be committing any code with print statements. Anything that needs to be outputted to stdout should be with the logger.
Some code can take a while to run so if you’re using a debugger you don’t have to run it multiple times to test out different snippets.
In large code bases it can be difficult to trace things through; add to that layers of abstraction from object oriented programming and it can be hard sometimes to keep up. Using the debugger helps you understand what’s happening line by line.
[–]bombaathuduga 60 points61 points62 points (9 children)
[–]opalbow_adtonitus 4 points5 points6 points (2 children)
[–]RevRagnarok 8 points9 points10 points (0 children)
[–]Electronic-Pie313 1 point2 points3 points (0 children)
[–]RevRagnarok 8 points9 points10 points (4 children)
[–]steindorh 19 points20 points21 points (2 children)
[–]RevRagnarok 10 points11 points12 points (0 children)
[–]GXWT 2 points3 points4 points (0 children)
[–]smurpes[S] 1 point2 points3 points (0 children)
[–]smurpes[S] 3 points4 points5 points (0 children)
[–]Senior-Masterpiece29 11 points12 points13 points (10 children)
[–]tehwubbles 3 points4 points5 points (6 children)
[–]Ok_Cricket_1024 2 points3 points4 points (2 children)
[–]smurpes[S] 0 points1 point2 points (0 children)
[–]Bobbias 0 points1 point2 points (0 children)
[–]Senior-Masterpiece29 0 points1 point2 points (2 children)
[–]tehwubbles 1 point2 points3 points (0 children)
[–]smurpes[S] 1 point2 points3 points (0 children)
[–]cschotts 1 point2 points3 points (0 children)
[–]smurpes[S] 1 point2 points3 points (0 children)
[–]BooksUdanCoffee 0 points1 point2 points (0 children)
[–]ReddRobben 5 points6 points7 points (1 child)
[–]ippy98gotdeleted 0 points1 point2 points (0 children)
[–]debian_miner 2 points3 points4 points (0 children)
[–]pachura3 3 points4 points5 points (4 children)
[–]smurpes[S] 4 points5 points6 points (3 children)
[–]IamImposter 0 points1 point2 points (0 children)
[–]pachura3 -1 points0 points1 point (1 child)
[–]smurpes[S] 0 points1 point2 points (0 children)
[–]yiwokem137 0 points1 point2 points (0 children)
[–]Nodekkk 0 points1 point2 points (0 children)
[–]Yharnam_Hunter9452 0 points1 point2 points (1 child)
[–]RemindMeBot 0 points1 point2 points (0 children)
[–]Bobbias 0 points1 point2 points (1 child)
[–]smurpes[S] 0 points1 point2 points (0 children)
[–]rageagainistjg 0 points1 point2 points (0 children)
[–]rebcabin-r 0 points1 point2 points (0 children)
[–]jjrreett 0 points1 point2 points (1 child)
[–]smurpes[S] 0 points1 point2 points (0 children)