为什么termcolor在python中不起作用? [英] Why termcolor doesn't work in python?

查看:1385
本文介绍了为什么termcolor在python中不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚在Python 2.7中安装了termcolor,当我尝试打印彩色而不是着色我的文本时,我得到的代码我猜颜色打印。任何帮助?

I just installed termcolor in Python 2.7 and when I try to print something colored instead of coloring my text I get the code I guess of color printed. Any help?

from termcolor import colored
print colored('Text text text', 'red')

以下是结果:

推荐答案

要使用termcolor中使用的ANSI颜色与Windows终端配合使用,您还需要导入/ init colorama ;

To make the ANSI colors used in termcolor work with the windows terminal, you'll need to also import/init colorama;

>>> from termcolor import *
>>> cprint('hello', 'red')
←[31mhello←[0m
>>> import colorama
>>> colorama.init()
>>> cprint('hello', 'red')
hello                                    <-- in red color
>>>

这篇关于为什么termcolor在python中不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆