本文介绍了适用于Python的Colorama,在Windows上不返回彩色打印行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经为python安装了colorama.我已按如下所示导入了模块:
I've installed colorama for python. I've imported the module as follows:
import colorama
from colorama import init
init()
from colorama import Fore, Back, Style
print Fore.RED + "My Text is Red"
并返回ANSI字符....
and it returns the ANSI charaters....
esc[31mMy Text is Red
这不是我所期望的.我在做错什么吗?
This isn`t what I expected. Am I doing something wrong.
谢谢.
推荐答案
我在Windows 7 x64上也遇到了同样的问题,我终于有了颜色,而不必在初始化中添加参数convert=True
来安装任何新东西.打电话.
I had this same issue on Windows 7 x64, I finally got the colors working without having to install anything new just by adding the argument convert=True
to the init call.
from colorama import init, Fore, Back, Style
init(convert=True)
print(Fore.RED + 'some red text')
这篇关于适用于Python的Colorama,在Windows上不返回彩色打印行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!