Text Properties

Text colors:

  • grey
  • red
  • green
  • yellow
  • blue
  • magenta
  • cyan
  • white

Text highlights:

  • on_grey
  • on_red
  • on_green
  • on_yellow
  • on_blue
  • on_magenta
  • on_cyan
  • on_white

Attributes:

  • bold
  • dark
  • underline
  • blink
  • reverse
  • concealed

我们用ipython工具显示termcolor 模块的功能:

显示termcolor主要功能

In [3]: from termcolor import
ATTRIBUTES HIGHLIGHTS VERSION cprint print_function
COLORS RESET colored os

文本颜色常量字典
In [5]: from termcolor import COLORS as textcolors

In [6]: print textcolors
{‘blue’: 34, ‘grey’: 30, ‘yellow’: 33, ‘green’: 32, ‘cyan’: 36, ‘magenta’: 35, ‘white’: 37, ‘red’: 31}

高亮文本常量字典

print HIGHLIGHTS
{‘on_cyan’: 46, ‘on_white’: 47, ‘on_grey’: 40, ‘on_yellow’: 43, ‘on_blue’: 44, ‘on_magenta’: 45, ‘on_red’: 41, ‘on_green’: 42}

知道这些文本常量,我们就可以随机显示打印文本的颜色!是不是很方便。