I am trying to change the colour of a certain line of text. I have looked at other articles (including Change shell print color in python 3.3.2 ) but none of the work. I would not like to install any external modules if that is possible.
My code:
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.')
I am using Python 3.2.3 on Linux. Thanks for any responses.
I think the way you are using is aimed at Windows.
You may use termcolor
:
from termcolor import colored
print colored('hello', 'red'), colored('world', 'green')
You may use also color formatting codes listed here , use them like that:
>>> 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.
Output would be like:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.