Colored text in Linux

David Porter jcm at bigskytel.com
Thu Sep 21 21:20:47 CEST 2000


* Brian Geddes <brian.j.geddes at intel.com>:
> 
> I want to be able to print out colored text to the screen from inside a
> Python script in Linux.  I figure this is just a matter of using the proper
> escape codes, but I'm not sure where to find them or if I'll have to use
> anything other than the basic print() function.  Thanks in advance...
> 

These should work (taken from pydf):

colours = { 'default'    :    "\033[0m",
            'bold'       :    "\033[1m",
            'underline'  :    "\033[4m",
            'blink'      :    "\033[5m",
            'reverse'    :    "\033[7m",
            'concealed'  :    "\033[8m",

            'black'      :    "\033[30m", 
            'red'        :    "\033[31m",
            'green'      :    "\033[32m",
            'yellow'     :    "\033[33m",
            'blue'       :    "\033[34m",
            'magenta'    :    "\033[35m",
            'cyan'       :    "\033[36m",
            'white'      :    "\033[37m",

            'on_black'   :    "\033[40m", 
            'on_red'     :    "\033[41m",
            'on_green'   :    "\033[42m",
            'on_yellow'  :    "\033[43m",
            'on_blue'    :    "\033[44m",
            'on_magenta' :    "\033[45m",
            'on_cyan'    :    "\033[46m",
            'on_white'   :    "\033[47m" }

Yes, you can use them with print.


  David



More information about the Python-list mailing list