Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

Saichand Pullepu
Saichand Pullepu
11,905 Points

How to debug Python code

I am doing the Beginning Python Track. I am into Object Oriented Python Course. Still there is no video on how to DEBUG the Python code.

2 Answers

Jeff Muday
MOD
Jeff Muday
Treehouse Moderator 28,717 Points

There are some courses at Treehouse about testing in various languages-- that is debugging of sorts!

https://teamtreehouse.com/library/python-testing

I would agree with you on this point, that there is no actual debugging Python workshop. Maybe I should get off the bench and do that for Treehouse!

Everyone at some point comes up with a strategy-- which at it's simplest may be to include print() statements at critical parts of the code. Eventually, you might use the Python Debugger (PDB) which has a pretty rich set of possibilities. The PDB can put in a breakpoint on your code and at that point you get an interactive prompt to examine variables, etc. Or you can choose to do "postmortem" checks if a part of your program throws a particular error.

https://docs.python.org/3/library/pdb.html

Some of the better IDEs Integrated Development Environments have very nice integrated debugging capabilities. Pycharm Edu and Wingware Personal (which is my favorite) by default have the ability to set breakpoints, watches, etc. VisualStudio Code (VSC) is a little more work to set up, but has pretty excellent debugging and a bit more lightweight than PyCharm. VSC is getting very popular and runs on Mac, Linux, and Windows.

Treehouse has some workshop material on PyCharm which I heartily recommend (it is short-- like 25 minutes, but you can see how PyCharm has some very nice development tools to offer, and maybe a good choice for full-stack developers since its parent company JetBrains is dedicated to developing tools for all the major platforms-- PHP, Java, Ruby, Javascript, etc.

https://teamtreehouse.com/library/pycharm

I have spoken about this before but in my opinion, *WingWare IDE is exceptionally strong. * I license the Pro version, but the Personal version (which is free to use for learning and personal projects) has all the features needed by an independent developer to do some great stuff. Again, like its competitors, this program works on Linux, Windows, and Mac.

https://wingware.com/

Good luck with your Python journey!