2024-05-19 08:11:06 发布
网友
我刚刚在Windows上安装了Python 2.7的termcolor。当我尝试打印彩色文本时,我得到的是彩色代码。
from termcolor import colored print colored('Text text text', 'red')
结果如下:
我在Far管理器上获得了相同的结果,当我尝试将脚本作为独立应用程序运行时。
要使termcolor中使用的ANSI颜色与windows终端协同工作,还需要导入/init^{}
>>> from termcolor import * >>> cprint('hello', 'red') ←[31mhello←[0m >>> import colorama >>> colorama.init() >>> cprint('hello', 'red') hello <-- in red color >>>
要使termcolor中使用的ANSI颜色与windows终端协同工作,还需要导入/init^{}
相关问题 更多 >
编程相关推荐