Python_ console Output Color-colored text method

Source: Internet
Author: User

Reprint to http://www.cnblogs.com/yinjia/

In the development of the project, in order to facilitate debugging code, often to stdout output some logs, the default of these logs are directly displayed in the terminal. And the general application server, third-party libraries, and even some of the server's announcements are also displayed in the terminal, which disturbs the information we want.

The writing format, and the related instructions are as follows:

1 Format: \033[display mode; foreground color; background colour m23Description4Foreground background color5---------------------------------------6 30 40Black7 31 41Red8 32 42Green9 33 43Yellow color10 34 44Blue11 35 45Purplish red12 36 46Cyan Blue13 37 47 white 14  show way meaning 15-------------------------16 17 1 highlight 18 4 use underline Span style= "color: #008080;" >19 5 blinking 20 7 anti-white display 21 8 invisible 22 23  example: 24 \033[1;31;40m <!--1-highlight 31-foreground color Red 40-background black-- 25 \033[0m <!--with the terminal default setting, which cancels the color setting-->        

Example:

1Print‘\033[1;31;40m‘)2Print‘*' * 50)3Print‘*host:\t', 2002)4Print‘*uri:\t‘,‘http://127.0.0.1‘)5Print ' *args:\t) 6 *time:\t ",  22:28< Span style= "color: #800000;" > '  ' 7 print ( '                 

Operation Result:

Description: http://127.0.0.1 white display is wrong!!!

Python_ console Output Color-colored text method

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.