更改Python文本的颜色

更改Python文本的颜色,python,colors,passwords,Python,Colors,Passwords,我试图改变某一行文字的颜色。 我看过其他的文章(包括),但没有一篇是我的作品。 如果可能的话,我不想安装任何外部模块 我的代码: from subprocess import call call('color a', shell=True) #this sets the color to light green print('The quick brown fox jumps over the lazy dog.') 我正在Linux上使用Python 3.2.3。 谢谢你的回复 我认为您使用

我试图改变某一行文字的颜色。 我看过其他的文章(包括),但没有一篇是我的作品。 如果可能的话,我不想安装任何外部模块

我的代码:

from subprocess import call
call('color a', shell=True) #this sets the color to light green
print('The quick brown fox jumps over the lazy dog.')
我正在Linux上使用Python 3.2.3。
谢谢你的回复

我认为您使用的方式是针对Windows的

您可以使用
术语color

from termcolor import colored

print colored('hello', 'red'), colored('world', 'green')

您也可以使用列出的颜色格式代码,如下所示:

>>> text = "The quick brown fox jumps over the lazy dog."
>>> print('\033[1;32m'+text+'\033[1;m')
The quick brown fox jumps over the lazy dog.
输出如下所示:


试试这个:。@Dylan,它给了你什么错误:
/bin/sh:1:color:找不到
?您使用的是linux还是windows?我当前使用的是linux。@DylanMurphy它显示您在运行代码时出现了什么错误?可能的重复项不起作用,但还是要感谢您。我仍然会将此标记为最佳答案。您必须首先安装termcolor:在Windows Powershell中,pip安装termcolor,或Mac终端:pip3安装termcolor