2

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.

Community
  • 1
  • 1

1 Answers1

0

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:

enter image description here

Assem
  • 11,574
  • 5
  • 59
  • 97
  • Does not work but thanks anyway. I will still mark this as the best answer. –  Dec 21 '15 at 20:02
  • You have to install termcolor first: in Windows Powershell pip install termcolor, or Mac Terminal: pip3 install termcolor – Valy Jun 10 '21 at 15:27