Jordan Baron Jordan Baron - 1 month ago 18
Python Question

Terminal colors change in Python

I have this code

import sys
#Jordan Run Game
class Character():

def __init__(self, role):
print "\033[91m Warrior \033[96m Mage"
charRole = raw_input()

if charRole == "Warrior":
self.role = "Warrior"
elif charRole == "Mage":
self.role = "Mage"
elif charRole == "Rouge":
self.role = "Rouge"
elif charRole == "Healer":
self.role = "Healer"
else:
sys.exit()

print "You chose %s" % self.role

character = Character(role = "")


The colors change, but for some reason every color changes.

For example, Mage is in blue, and so is every text after that.

enter image description here

Answer

You need to terminate the color

'\033[0m'

so you want

 print "\033[91m Warrior \033[96m Mage\033[0m"
Comments