How to properly debug your python script

Akinwande Komolafe
6 min readAug 31, 2022

Learn how to properly debug your Python script with the Logging Python library

The first thing we learn as software engineers when learning a new programming language is how to print “Hello World” in the console. From Python’s documentation , ‘print’ statement is best used to display console output for ordinary usage of a command line script or program.

Even when we have mastered the language, we still end up using print statements when debugging. Of course, it is easy and convenient to display quick messages when we are unsure of anything. I was also guilty of this and I had the habit of including print statements in my code while debugging. I decided to try out the loggingmodule in Python and so far I am comfortable with it.

In this article, I will explain

  1. Why you should use logging instead of print statement
  2. Fundamentals of Logging

Why you should use logging instead of print statement

  1. It is a bad practice to use ‘print’ if your project is intended to be imported by other Python tools since the user won’t know where the print messages are coming from.
  2. With Logging, users of your package can select whether or not to propagate logging messages from your utility…

--

--