如何在Python中将彩色文本输出到终端?表示实体块的最佳Unicode符号是什么?
perl的是否有任何python等价物
print color 'red';
print <something>;
print color 'reset';
Run Code Online (Sandbox Code Playgroud)
在python中可用?
我知道解决方案;
"\x1b[1;%dm" % (<color code>) + "ERROR: log file does not exist" + "\x1b[0m"
Run Code Online (Sandbox Code Playgroud)
我想要的是我应该能够为所有打印消息设置颜色,比如
print color 'red'
function_print_something(<some message>)
print color 'reset'
Run Code Online (Sandbox Code Playgroud)
这里'function_print_something'是我的python函数,它会将一些格式化的日志消息打印到屏幕上.
如果我在linux下的python中运行它可以工作:
start = "\033[1;31m"
end = "\033[0;0m"
print "File is: " + start + "<placeholder>" + end
Run Code Online (Sandbox Code Playgroud)
但是,如果我在Windows中运行它不起作用,我怎样才能使ANSI转义码在Windows上运行?