When you first start programming in any language, you’re often taught to print()
to the console in order to see the values of variables or just to help you debug.
As a beginner, this is an acceptable technique. As you advance in your programming career, you find out sooner or later, that print()
-ing to the console to debug is easy, but comes with a lot of drawbacks. But what else should you do?
Use the debugger and use the Logging module instead.
Python created “PEP-282 — A Logging System” back in February 2002! https://www.python.org/dev/peps/pep-0282/
It was inspired by other logging packages of other languages. Logging is a little bit more complex than print()
, but it is much better suited to debugging your program than print()
.