好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

Python:如何使ANSI转义码在Windows中也能正常工作?

如果我在 Linux 下的 python中运行它可以工作:

start = "\033[1;31m"
end = "\033[0;0m"
print "File is: " + start + "<placeholder>" + end

但是,如果我在Windows中运行它不起作用,我怎样才能使ANSI转义码在Windows上运行?

您可以检查 Python module to enable ANSI colors for stdout on Windows?以查看它是否有用.

colorama模块似乎是跨平台的.

你安装colorama:

pip install colorama

然后:

import colorama
colorama.init()
start = "\033[1;31m"
end = "\033[0;0m"
print "File is: " + start + "<placeholder>" + end

查看更多关于Python:如何使ANSI转义码在Windows中也能正常工作?的详细内容...

  阅读:25次