Colorful Python (change the font color and style)

Colorful python (change the font color and style)

In the course of the project, we often feel that because of the color of the output information in the visual style too monotonous very messy, so look below:

在Linux终端中,使用转义序列来进行如上所述的显示,转义序列以ESC开头,即ASCII码下的\033,其格式为:\033[显示方式;前景色;后景色m      # 开头`
     
注意:显示方式、前景色、背景色至少存在一个。
     
\033[显示方式m   # 结尾,如果不结尾会影响到后续的输出,其中说明将在下文给出

Corresponding to the color table:

Foreground After scenery colour
30 40 black
31 41 red
32 42 green
33 43 yellow
34 44 blue
35 45 Fuchsia
36 46 cyan
37 47 white

Corresponding to the display mode:

Display method significance
0 The default setting terminal
1 Highlight
4 Use an underscore
5 flicker
7 Highlight
8 Invisible

Example:

\033[1;31;40m    <;!--1-高亮显示 31-前景色红色  40-背景色黑色-->;
\033[0m          <;!--采用终端默认设置,即取消颜色设置-->;
print("\033[1;31;40m你好!\033[0m ")

Colors under Windows debugging:

Python code style or color display can be seen only in a portion interpreter, because they are mainly used in the Linux system, the Linux system, the terminal may output color text or control character by curse module, but in the windows system no curse module nor can control characters, if you want to display a certain color and style in Windows, you can import conselo package, the module console correlation function can help us to color and display code changes.

We can first be installed console package, enter the console pip install console, then open the python, import consoleJiuhaola, then you can really open the python colorful life of it!

The following is my test content:


Additional content:

Guess you like

Origin www.cnblogs.com/nickchen121/p/11270638.html