[Tutor] Print to std output with color

Tim Golden mail at timgolden.me.uk
Wed Jan 26 20:31:58 CET 2011


On 26/01/2011 6:10 PM, Scott Nelson wrote:
> Curses is one way to go.  Another is to use the PyWin32 module discussed in
> this thread:
>
> http://thread.gmane.org/gmane.comp.python.tutor/58450/focus=58454
>
> Basically, here's a snippet of code that can get you started.  This requires
> that you have the PyWin32 module installed (already installed by default if
> you use ActiveState's Python distribution for Windows).  Using PyWin32 isn't
> for the faint of heart, but it does work.
>
> import win32console
> handle = win32console.GetStdHandle(win32console.STD_OUTPUT_HANDLE)
> handle.SetConsoleTextAttribute(win32console.FOREGROUND_BLUE)
> print 'blue text'

Or use something which does it for you already:

   colorama -- http://tartley.com/?p=1062

TJG


More information about the Tutor mailing list