It's fine to use a few print
statements while you're working code in a jupyter notebook. You should, however, remove these from production code. A logging framework should be used instead when you want structured information from your application.
Thankfully, there's a lovely flake8-print plugin that checks for print
-statements and can help prevent them from getting into git. It works via flake8, check out our guide if you aren't familiar with it yet.
You can install the tool via:
python -m pip install flake8-print
Once it's installed you can simply flake8 just like you're used to.
python -m flake8
It will throw extra errors when print is still detected in the codebase. It's especially powerful when it's used in combination with pre-commit hooks.
Back to main.