微慑信息网

[python] 输出颜色 - colorama / termcolor [补充]

之前使用termcolor,最近看到有colorama,发现更加简单。。

1、termcolor

from termcolor import colored, cprint

str = colored(str(mTypeName), 'red','on_white',attrs=None)

 

2、colorama

from colorama import Fore,Back,Style,init

def main():
	#init(autoreset=True)
	print(Style.RESET_ALL)
	str = Fore.RED + " let me see see"
	print (str)
	print (Fore.WHITE +"let me see see")
if __name__ == '__main__':
	main()

补充,在使用colorama时,容易导致赋色字符串后面都是同一颜色的情况,如:

可做如此设置:

str = Fore.RED + " let me see see" + Style.RESET_ALL

即可,

如:

 

 

 

赞(0) 打赏
转载请附本站链接,未经允许不得转载,,谢谢:微慑信息网-VulSee.com » [python] 输出颜色 - colorama / termcolor [补充]

评论 抢沙发

微慑信息网 专注工匠精神

微慑信息网-VulSee.com-关注前沿安全态势,聚合网络安全漏洞信息,分享安全文档案例

访问我们联系我们

觉得文章有用就打赏一下文章作者

非常感谢你的打赏,我们将继续提供更多优质内容,让我们一起创建更加美好的网络世界!

支付宝扫一扫打赏

微信扫一扫打赏

登录

找回密码

注册