I'm kind of a beginner in Python, and I wanted to highlight some text printed out such as warning, bold whatsoever, using ANSI values.
I found this question (Print in terminal with colors using Python?) in Stack Overflow and I kind of used my own approach:
import sys
def hilite(status, string = ''):
if sys.stdout.isatty():
# Header # Ok Blue #Ok Green # Warning # Fail # Bold # Underline
attr = ['\033[95m', '\033[94m', '\033[92m', '\033[93m', '\033[91m', '\033[1m', '\033[4m']
ENDC = '\033[0m'
print(attr[status]+ string +ENDC)
else:
print(string)
# header
hilite(0, '\t\t\t\tMy Python program')
Output:
←[95m My Python program←[0m
I tried the original approach but same results. I'm using Windows.