Termcolor -- use Python to output color terminal information

Source: Internet
Author: User
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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.