Python:如何使 ANSI 转义码也能在 Windows 中工作? [英] Python: How can I make the ANSI escape codes to work also in Windows?
本文介绍了Python:如何使 ANSI 转义码也能在 Windows 中工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我在 linux 下的 python 中运行它,它可以工作:
If I run this in python under linux it works:
start = " 33[1;31m"
end = " 33[0;0m"
print "File is: " + start + "<placeholder>" + end
但是如果我在 Windows 中运行它就行不通了,我怎样才能让 ANSI 转义码在 Windows 上也能工作?
But if I run it in Windows it doesn't work, how can I make the ANSI escape codes work also on Windows?
推荐答案
对于 windows,调用 os.system("color") 使 ANSI 转义序列得到正确处理:
For windows, calling os.system("color") makes the ANSI escape sequence get processed correctly:
import os
os.system("color")
COLOR = {
"HEADER": "