I want to change color of text. And when I try it in VS code it works. But when I try it in CMD in Windows I get this:
←[91mstring
Code in python:
print ('\033[91m' + "string")
I want to change color of text. And when I try it in VS code it works. But when I try it in CMD in Windows I get this:
←[91mstring
Code in python:
print ('\033[91m' + "string")
There is a "bug" in cmd. You need to first clear the screen with:
import os
os.system("cls")
Than it should work.
Full code:
import os
os.system("cls")
print('\033[91m' + "string")
I hope my answer will help.
This is how to use it properly :
import os
os.system("cls")
print('\033[91m' + "string")
There is also the Python termcolor module. Usage is pretty simple:
from termcolor import colored
print(colored('string', 'red'), colored('string', 'green'))