本文介绍了Colorama for Python,在 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
到 init 调用.
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')
这篇关于Colorama for Python,在 Windows 上不返回彩色打印线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!