我知道这个问题已在提出在Stackoverflow here如何打印在Python终端丰富多彩的文本?
所以我试了下面的代码从joeld
的答案。
这里是IDLE(我使用Python 2.7)的代码:
print '\033[95m'+'my text'+'\033[95m'
和我没有颜色输出变化:
[95mmy text[95m
========= ================================================== ====================
然后我也尝试了包colorama
。该软件包安装内cmd
:
python setup.py install
,并试图在之后的Aptana Studio的3码:
from colorama import *
print (Fore.GREEN + 'Green text')
print (Fore.Red + 'Red text')
我得到了以下的输出:
[32mGreen text
Traceback (most recent call last):
File "C:\Users\My Documents\Aptana Studio 3 Workspace\Practice\test_colorama.py", line 12, in <module>
print (Fore.Red + 'Red text')
AttributeError: 'AnsiCodes' object has no attribute 'Red'
======== ================================================== =====================
所以,现在我真的很ç onfused。这些解决方案的数量高达数百倍,这意味着它应该是有效的,但在我看来并不是这样。
可我知道我可以在终端或控制台打印色彩鲜艳的文字?
非常感谢。
也许'RED'而不是'Red'? – Bach
我想你的第一个例子中香草CPython的外壳,并且在外壳的IPython,和它的工作两次。 –
也有几个终端:)如果你提到你使用了哪一个,那将会很棒。有些终端根本不支持彩色。 –