Printing Colors In Python Terminal
I'd like to make a program that prints colors in the python terminal but I don't know how. I've heard that you can use certain escape sequences to print text in color, but I'm not
Solution 1:
Try the termcolor
module.
from termcolor import colored
print colored('hello', 'red'), colored('world', 'green')
See Print in terminal with colors using Python?
Also, you could use ANSI codes:
classbcolors:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'defdisable(self):
self.HEADER = ''
self.OKBLUE = ''
self.OKGREEN = ''
self.WARNING = ''
self.FAIL = ''
self.ENDC = ''print(bcolors.WARNING + "Warning" + bcolors.ENDC)
Post a Comment for "Printing Colors In Python Terminal"