termcolor:给python打印出彩色文字

环境: centos5.5+python2.7

用到的块模: termcolor

下载地址: http://pypi.python.org/pypi/termcolor/0.1.1

安装比较简单:

tar zxvf termcolor-0.1.1.tar.gz

cd termcolor-0.1.1

python setup.py install

使用说明:

>>> dir(colored)
[‘call‘, ‘class‘, ‘delattr‘, ‘dict‘, ‘doc‘, ‘get‘, ‘getattribute‘, ‘hash‘, ‘init‘, ‘module‘, ‘name‘, ‘new‘, ‘reduce‘, ‘reduce_ex‘, ‘repr‘, ‘setattr‘, ‘str‘, ‘func_closure’, ‘func_code’, ‘func_defaults’, ‘func_dict’, ‘func_doc’, ‘func_globals’, ‘func_name’]
>>> print colored.doc
Colorize text.

Available text colors:
red, green, yellow, blue, magenta, cyan, white.

Available text highlights:
on_red, on_green, on_yellow, on_blue, on_magenta, on_cyan, on_white.

Available attributes:
bold, dark, underline, blink, reverse, concealed.

Example:
colored(‘Hello, World!’, ‘red’, ‘on_grey’, [‘blue’, ‘blink’])
colored(‘Hello, World!’, ‘green’)

 

例子: