Python output with color text in Linux

Source: Internet
Author: User

In order to make the output more beautiful and eye-catching, sometimes you need to add some color to the Python output characters, very simple to share the following method:


Format: \033[display mode; foreground color; background colour m

Foreground background color

---------------------------------------

30 40 Black

31 41 Red

32 42 Green

33 43 Yellow

34 44 Blue

35 45 Purplish red

36 46 Cyan Blue

37 47 White


Meaning of display mode

-------------------------

0 Terminal default settings

1 highlighting

4 using underscores

5 Flashing

7 Anti-white display

8 Not visible


#linux终端中的颜色是用转义序列控制的, the escape sequence starts with the ESC and can do the same with \033 (the ASCII code for ESC is 27 in decimal notation, which equals 33 in octal).

..........................................................

#!/usr/bin/ev python

Print "\033[31m.\033[0m" * 30

Print "\033[1;33;44m"

Print "AAAAAAAAAAAAAAAAAAAAAA"

Print "BBBBBBBBBBBBBBBBBBBBBB"

Print "\033[0m"

Print "\033[31m.\033[0m" * 30

..........................................................

Effect

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/77/0B/wKioL1ZhYaywOxpmAAApgGQHhdE524.png "title=" 1.png " alt= "Wkiol1zhyaywoxpmaaapggqhhde524.png"/>

This article is from the "Rookie Growth Road" blog, please be sure to keep this source http://francis905.blog.51cto.com/3048056/1719673

Python output with color text in Linux

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.