前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >python的termcolor模块

python的termcolor模块

作者头像
周小董
发布2019-03-25 11:22:43
9050
发布2019-03-25 11:22:43
举报
文章被收录于专栏:python前行者python前行者

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对属性的支持如下:

Terminal

bold

dark

underline

blink

reverse

xterm

yes

no

yes

bold

yes

linux

yes

yes

bold

yes

yes

rxvt

yes

no

yes

bold/black

yes

dtterm

yes

yes

yes

reverse

yes

teraterm

reverse

no

yes

rev/red

yes

aixterm

normal

no

yes

no

yes

PuTTY

color

no

yes

no

yes

Windows

no

no

no

no

yes

Cygwin SSH

yes

no

color

color

color

Mac Terminal

yes

no

yes

yes

yes

示例代码:

代码语言:javascript
复制
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)

文档:https://pypi.org/project/termcolor/

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2018年08月06日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档