Python – Logging in Python. Formatting with Black

Logging in Python is beautifully implemented with the logging library – https://docs.python.org/3/howto/logging.html

It simply does anything you need and you do not need to write something yourself, like I did some time ago here in my VBA Boilerplate.

A nice forest path, with no log once you walk through it.

So, if you are coming from the VBA world (which you are probably not, but you are browsing this site, so you never know…), you will be amazed how neat the logging is done in python. The “beauty” below makes a logging file and adds data to it, whenever it is accessed:

Yup. The logging is beautiful:

Quite what we expected.

Formatting with Black

And speaking of beautiful, take a look at the black formatter here – https://github.com/psf/black.

After you install it with pip install black it is quite nice and to run it you only need these lines:

python3 -m black name-of-file.py – works for the explicitly mentioned python file.

python3 -m black . – works for each python file in the whole directory.

That’s all!

Tagged with: , , ,