Why printing in color in a Windows terminal in Python does not work? [duplicate]

限于喜欢 提交于 2021-02-08 07:27:32

问题


I can print test1 in green and test2 in red in ipython :

print ('\033[92m' + "test1")
print ('\033[91m' + "test2")

But gives me the following error printed in white in the terminal :

[92mtest1
[91mtest2

回答1:


Windows terminal doesn't handle ansi coding for coloring text like other (vt100 compatible) terminals. If you want to be able to color your output in windows your best bet is likely going to be something like colorama, Ansicon or some other external program to handle colorizing output to the windows terminal.



来源:https://stackoverflow.com/questions/60218097/how-to-have-colored-text-displayed-after-converting-script-into-a-exe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!