If I run this in python under linux it works:
JavaScript
x
4
1
start = "33[1;31m"
2
end = "33[0;0m"
3
print "File is: " + start + "<placeholder>" + end
4
But if I run it in Windows it doesn’t work, how can I make the ANSI escape codes work also on Windows?
Advertisement
Answer
For windows, calling os.system("")
makes the ANSI escape sequence get processed correctly:
JavaScript
1
13
13
1
import os
2
os.system("") # enables ansi escape characters in terminal
3
4
COLOR = {
5
"HEADER": "33[95m",
6
"BLUE": "33[94m",
7
"GREEN": "33[92m",
8
"RED": "33[91m",
9
"ENDC": "33[0m",
10
}
11
12
print(COLOR["GREEN"], "Testing Green!!", COLOR["ENDC"])
13