首页 技术 正文
技术 2022年11月21日
1 收藏 361 点赞 2,687 浏览 1348 个字

termcolor是python中标注文本颜色的库

ANSII Color formatting for output in terminal. 利用termcolor查看log,进行代码调试,清晰标出自己想要查看的部分。

帮助文档

FUNCTIONS
colored(text, color=None, on_color=None, attrs=None)
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') cprint(text, color=None, on_color=None, attrs=None, **kwargs)
Print colorize text.It accepts arguments of print function.DATA
ATTRIBUTES = {'blink': 5, 'bold': 1, 'concealed': 8, 'dark': 2, 'rever...
COLORS = {'blue': 34, 'cyan': 36, 'green': 32, 'grey': 30, 'magenta': ...
HIGHLIGHTS = {'on_blue': 44, 'on_cyan': 46, 'on_green': 42, 'on_grey':...
RESET = '\x1b[0m'
VERSION = (1, 1, 0)
__ALL__ = ['colored', 'cprint']
print_function = _Feature((2, 6, 0, 'alpha', 2), (3, 0, 0, 'alpha', 0)...

color:字体颜色,on_color:背景颜色

代码样例

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)

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,910
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,435
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,250
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,061
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,693
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,731