How to Print Colored Text in Python

python_tutorials

Introduction

It’s typical for CLI apps to return text in the same color of the terminal. There are always cases when we want to highlight output to the user, for example, a warning or error message. In those cases, a dash of color could make a difference.

This article shows you how to print colored output in the terminal in Python with and without libraries.

ANSI Escape Sequences

Your Teletypewriter (TTY), or rather your terminal, is not only capable of showing the output of a program. It can display a moving cursor, color the text, clear the entire screen, and much more than just static output. You may have seen command-line utilities with colorful text and progress bars. How do we control the presentation of the data we’re are outputting to the terminal?

We use ANSI Escape Sequences/Codes. These are special strings that modify the behavior of

 

 

To finish reading, please visit source site