[Tutor] Print to std output with color

Scott Nelson sirgnip at gmail.com
Wed Jan 26 19:10:33 CET 2011


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'

On Wed, Jan 26, 2011 at 11:10 AM, Karim <karim.liateni at free.fr> wrote:

>
> Hello all,
>
> Is there a simple way to print with color to stdout like the unix/linux
> example below:
>
> *print( '^[[1;31mThis is a warning!^[[0m' )
>
> where <Ctrl-V><esc> <=> ^[
>
> *I see thing with curses module. But is there an more simple object in
> other module to do the trick?
> Kind of *decorate_output( mode=WARNING, 'This is a warning!')*
>
> Regards
> Karim
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110126/a1e7c7b8/attachment.html>


More information about the Tutor mailing list