Python f-string Debug Tip
This post will be a quick one. I see a lot of f-string debug statements in pair programming like below;
|
|
First of all, it’s better to use python’s built-in logging
module.
|
|
Note
For a detail information about logging
, you can look at my previous article:
python logging config.
Since python 3.8 you can use a =
at the end of a expression without hard
coding variable/expression:
|
|
This which is equal to f"os_user = {os_user}"
, will enforce the variable to
also be logged/printed.
[2023-03-26 22:48:43 +0300] [INFO ] : os_user = 'user'
Note
It’s usually best to use a proper debugger
. They are built-in in IDEs
like VScode or PyCharm. You can also take advantage of separate ones as well
such as pdb
, ipdb
etc, or my favorite one pudb
.
All done!
Changelog
- 2022-03-23 : Add stdout code
Subscribe
Read Related