Python Forum
Thread Rating:
  • 3 Vote(s) - 2.67 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to print in colors
#1
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
Reply
#2
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)
   


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

https://pypi.python.org/pypi/colorama
Recommended Tutorials:
Reply
#3
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
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Count image's colors very fast flash77 18 1,304 Mar-05-2024, 06:12 PM
Last Post: deanhystad
  can openpyxl read font colors mperemsky 3 1,656 May-09-2023, 11:18 AM
Last Post: MindKeeper
  ANSI not working for change of text colors BliepMonster 10 3,251 Nov-10-2022, 09:28 AM
Last Post: BliepMonster
  How to do bar graph with positive and negative values different colors? Mark17 1 5,007 Jun-10-2022, 07:38 PM
Last Post: Mark17
  Plot Back Ground Colors JoeDainton123 0 2,169 Aug-19-2020, 11:09 PM
Last Post: JoeDainton123
  How to fill between the same area with two different colors Staph 0 1,463 Jul-08-2020, 07:01 PM
Last Post: Staph
  How do I map a list of values to specified colors? larkypython 4 2,506 Nov-05-2019, 09:22 AM
Last Post: larkypython
  after using openpyxl to add colors to script, black shows up white online in excel Soundtechscott 1 3,652 Jun-08-2019, 10:33 PM
Last Post: Soundtechscott
  How to plot two list on the same graph with different colors? Alberto 2 28,697 Jul-18-2017, 09:20 AM
Last Post: Alberto

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020