Today I would like to show you how to use masks to format your output data. Since I often have to monitor some log changes or processes I decided to show you how to monitor MySQL processes using python.
Caution! The following script uses an old syntax to format output data. The example works also with Python 3, but there is a new way to do this. For more details see the Format String Syntax page of the python 3 documentation.
I used this old formatting style, because I could not figure out how to limit the length of a string. I was just able to pad the output to a certain length, but if the input string was longer then the specified width, python did not care. So I would be most pleased to have your hints.
Also Python 3 uses a new formatting style, there is one advantage of this example. This fashion to format output using a mask is also used in many other languages like C/C++ and PHP, it is very easy to adopt this script. I would be happy to see some of your own implementations in your preferred programming language.
So until next time, happy coding!
Phidelux is a Computer Science MSc. interested in hardware hacking, embedded Linux, compilers, etc.