Article Title: termcolor -- use Python to output color terminal information. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
Messages printed on the terminal can be in color, but the coloring syntax is actually a little strange and hard to read.
Termcolor is a Python module that can help you output the Color Words of the terminal. Of course, the syntax is much better ~
After termcolor is installed, you only need:
FromTermcolor ImportColored
Then you can use the colored method to color the message, for example:
PrintColored ( 'Hello, World! ', 'Red' )
The red Hello World! will be printed !.
In addition, you can flip the background and foreground color of the font, and print messages with attributes like on_xxx with different background and font colors:
If complex color combinations are frequently used, lambda can be used to abstract parameters:
Red_on_cyan = LambdaX: colored (X, 'Red', 'On _ cyany' )
PrintRed_on_cyan ( 'Hello, World! ' )
Very convenient ~
Termcolor home page: http://pypi.python.org/pypi/termcolor/0.1.1