Everfighting
9/8/2017 - 8:56 AM

利用termcolor下的colored和cprint属性方便调试

import sys
from termcolor import colored, cprint
 
# 红色背景字符不发光
text = colored('Hello, World!', 'red', attrs=['reverse', 'blink'])
print(text)
 
# 红色背景上显示绿色字符
cprint('Hello, World!', 'green', 'on_red')
 
# 青蓝色背景上显示绿色字符
print_red_on_cyan = lambda x: cprint(x, 'red', 'on_cyan')
print_red_on_cyan('Hello, World!')
print_red_on_cyan('Hello, Universe!')
 
for i in range(10):
    cprint(i, 'magenta', end=' ')
 
# 红色字符加粗
cprint("Attention!", 'red', attrs=['bold'], file=sys.stderr)