Adding temporary print
statements to troubleshoot Python code is quick and dirty. And messy.
Incorporating logging
into your code habit is a great alternative to relying on ad-hoc print
statements that just need to get deleted later.
The Basics
import logging
logging.basicConfig(format='%(message)s', level=logging.DEBUG)
logger = logging.getLogger()
Toggle DEBUG mode off/on
logger.disabled = True
Try it yourself
my_var = 'ABC'
logging.debug(f'my_var = {my_var}')
Leave a Reply