Spice up your Python console applications
Matt Holder demonstrates how to use the Python Rich library to add formatting to your console applications.
RICH Credit: https://github.com/Textualize/rich
Part Two! Subscribe on page 16 to access past issues!
OUR EXPERT
Matt Holder has been a fan of the open source methodology for over two decades and uses Linux and other tools where possible. In his spare time, he enjoys listening to music and reading.
QUICK TIP
The code can be downloaded from https://github.com/mattmole/ LXF303-304-Python-Rich
In part two of our series on the Rich library, we are working through how to split our I terminal application into sections, using layouts, outlining information with panels, rendering links and markdown, and using the helper log function to render logs with the time the message occurred.
Each of the code samples below can be run separately or in one file, and they are also available from GitHub (see the Quick Tip). If you didn’t catch last month’s tutorial, the library can be installed using the following command from a terminal: pip install rich .
We use Visual Studio Code – it’s an excellent way to develop, debug and run code; follow the instructions at https://code.visualstudio.com/docs/setup/linux. When creating files in VSCode, make sure that any files are saved with a .py extension. Files can be run by pressing Ctrl+F5. If developing using another text editor, once the files have been saved, they can be run by entering python3 FILENAME.py in the terminal.