0

To put it briefly, I'd like to change the colour of separate strings being printed, using anything that comes with Python 3 (no modules as it's for a school thing).

I got as far as changing the colour of everything being printed, using this:

import os
os.system("Color 01")
print("Blue")

os.system("Color 02")
print("Green")

However, that just uses the last colour referenced ("Color 02" = Green). Would there be a way I could use this to set colour as intended, or by using something else in python?

Thanks in advance for any feedback.

Jememez
  • 1
  • 1
  • [This](https://stackoverflow.com/questions/37340049/how-do-i-print-colored-output-to-the-terminal-in-python/37340245#37340245) post has some alternatives. – atru Oct 11 '17 at 16:37
  • Thanks, not sure how I missed that @atru – Jememez Oct 11 '17 at 17:12
  • Does this answer your question? [How do I print colored output to the terminal in Python?](https://stackoverflow.com/questions/37340049/how-do-i-print-colored-output-to-the-terminal-in-python) – Tomerikoo Oct 06 '20 at 09:31

1 Answers1

0

You can print colored text by specifying the ANSI escape sequence

import os
os.system("color")

COLOR = {
    "HEADER": "\033[95m",
    "BLUE": "\033[94m",
    "GREEN": "\033[92m",
    "RED": "\033[91m",
    "ENDC": "\033[0m",
}

print(COLOR["GREEN"], "Testing Green!!", COLOR["ENDC"])
Gary Vernon Grubb
  • 9,695
  • 1
  • 24
  • 27