python 包之 termcolor 文本标注教程

一、安装

pip install termcolor

 

二、配置模式

  • colored:第一个参数为输出的字符串,第二个参数是颜色,第三个是属性配置

  • 效果:红色背景字符不发光

from termcolor import colored

text = colored('Hello, World!', 'red', attrs=['reverse', 'blink'])
print(text)

 

三、打印模式

  • cprint:直接通过打印模式进行配置背景色和文字颜色

  • 效果:红色背景上显示绿色字符

from termcolor import cprint

cprint('Hello, World!', 'green', 'on_red')

 

四、表达式模式

  • lambda:通过lambda表达式配置

  • 效果:青蓝色背景上显示绿色字符

from termcolor import cprint

print_red_on_cyan = lambda x: cprint(x, 'red', 'on_cyan')
print_red_on_cyan('Hello, World!')

 

五、其他样式

  • 效果:红色字符加粗

from termcolor import cprint

cprint('autofelix', 'red', attrs=['bold'], file=sys.stderr)

 

posted @   sunnyeden  阅读(303)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
点击右上角即可分享
微信分享提示