Python Forum

Full Version: How to print in colors
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
So I use python shell to do my stuff
but I want to print out in color I tried everything from ANSI escape routes or ansicolors but nothing everything i try it does not print out in color so my question is.
Can someone help me how to print out in color in shell thanks.
Yeah I know this is stupid question, but I cant find anwser anywhere
i just do something like...

RED='\033[0;31m'
GREEN='\033[1;32m'
INVERT='\033[1;3m'
NOCOLOR='\033[0m'
 
def print_color(msg, color):
    '''print in color in terminal'''
    s = '{}{}{}'.format(color, msg, NOCOLOR)
    print(s)
    
    
print_color('i am red', RED)
print('nothing')
print_color('i am green', GREEN)
[attachment=149]


There are modules to do such but i have never used them
https://pypi.python.org/pypi/termcolor

https://pypi.python.org/pypi/colorama
Colorama, termcolor, pygments
These I remember. There are more for sure

My favourite but I used it for something else: Blessings

Just pick one! Have fun, make a rainbow  Big Grin