LOGGING AND TESTING AND
DEBUGGING, OH MY!
@AlSweigart
[email protected]
(last name rhymes with “why dirt”)
bit.ly/ohmypy
Slide 2
Slide 2 text
Why?
Slide 3
Slide 3 text
LOGGING
Slide 4
Slide 4 text
LIVE DEMO!
Slide 5
Slide 5 text
This is terrible.
Slide 6
Slide 6 text
TERRIBLE
Print Debugging
Slide 7
Slide 7 text
Why do logging instead of print?
• Debug output vs. normal output
• Easier to remove debug messages.
• Easier to put debug messages back.
• Fine grain control with logging levels.
Slide 8
Slide 8 text
Logging
import logging
logging.basicConfig(
level=logging.DEBUG)
logging.debug('The log message.')
logging.disable(logging.CRITICAL)
Back to the live demo…
This is looks complicated.