termcolor模块

termcolor模块

termcolor是一个python包,可以改变控制台输出的颜色,支持各种terminal(WINDOWS的cmd.exe除外)。

它支持下列的文字颜色:
grey, red, green, yellow, blue, magenta, cyan, white

支持下列的背景高亮:
on_grey, on_red, on_green, on_yellow, on_blue, on_magenta, on_cyan, on_white

支持下列属性:
bold, dark, underline, blink, reverse, concealed

主流的terminal对termcolor的支持如下:

Terminalbolddarkunderlineblinkreverseconcealed
xtermyesnoyesboldyesyes
linuxyesyesboldyesyesno
rxvryesnoyesbold/blackyesno
dttermyesyesyesreverseyesyes
teratermreversenoyesrev/redyesno
aixtermnormalnoyesnoyesyes
PuTTYcolornoyesnoyesno
Windowsnonononoyesno
Cygwin SSHyesnocolorcolorcoloryes
Mac Terminalyesnoyesyesyesyes

示例代码

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)
#win7对以下命令无效
from termcolor import colored
print colored('hello', 'red'), colored('world', 'green')

第二个代码块的运行结果

转载于:
[1]: https://www.cnblogs.com/yrxns/p/7193062.html
[2]:https://blog.csdn.net/my2010Sam/article/details/12650957

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值