loading...

Make log Colorful with Python

kojikanao profile image Koji (he/him) Updated on ・1 min read

install colorama

$ pip install colorama

code

test.py

from colorama import Fore, Back, Style

print('===========================')
print(Fore.GREEN + "green string")
print(Style.DIM + "dim: test")
print(Style.BRIGHT + "BRIGHT: test")
print(Style.NORMAL + "NORMAL: test")
print(Style.RESET_ALL + "RESET_ALL")
print(Back.GREEN + 'green')
print(Style.RESET_ALL)
print('===========================')
print(Fore.RED + "red string")
print(Style.DIM + "dim: test")
print(Style.BRIGHT + "BRIGHT: test")
print(Style.NORMAL + "NORMAL: test")
print(Style.RESET_ALL + "RESET_ALL")
print(Back.RED + 'red')
print(Style.RESET_ALL)
print('===========================')
print(Fore.YELLOW + "yellow string")
print(Style.DIM + "dim: test")
print(Style.BRIGHT + "BRIGHT: test")
print(Style.NORMAL + "NORMAL: test")
print(Style.RESET_ALL + "RESET_ALL")
print(Back.YELLOW + 'yellow')
print(Style.RESET_ALL)
print('===========================')
print(Fore.BLUE + "blue string")
print(Style.DIM + "dim: test")
print(Style.BRIGHT + "BRIGHT: test")
print(Style.NORMAL + "NORMAL: test")
print(Style.RESET_ALL + "RESET_ALL")
print(Back.BLUE + 'blue')
print(Style.RESET_ALL)

result

Discussion

pic
Editor guide