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 Write Better Python Buggy Logs Logging

Michal Janek
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Michal Janek
Front End Web Development Techdegree Graduate 30,654 Points

So what is the outcome of this section?

Should we use PDB every time before we execute the code and then get rid of it? Should we always log everything into a log.file?

Can anyone more experienced in practice tell me if there is like a Zen practice / Mantra that we should follow regarding the logging/debugging concept in here.

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,457 Points

pdb and logging are tools to use only as needed. Many times writing tests will exercise the code to see if you get the desired output. If you're curious about intermediate states during execution or if there is unexpected behavior, then pdb and logging become very useful instead of adding print statements then deleting those. So the outcome of this section is to be exposed to tools to help you get to success. Though I still use print statement now and then.

Personally, I don't use pdb very often mainly because I can usually find my mistakes through tests, printing, and inspection. I find pdb very useful when inspecting unfamiliar code. I usually save logging for mature projects when I would like to track code behavior for future debug or general data collection.