Coloring print lines

S

Sami Viitanen

Hello,

Is there an easy way to make script print text with differents colors to
screen (shell)?

I mean a script that can for example print lines in red if some error occurs
in executing
some information..

--SV

----Thanks in advance.
 
S

Sybren Stuvel

Sami Viitanen enlightened us with:
Is there an easy way to make script print text with differents colors to
screen (shell)?

Sure, just use ANSI codes.
I mean a script that can for example print lines in red if some
error occurs in executing some information..

Example:

print "\033[31;1mError:\033[0m some message"

Sybren
 
?

=?ISO-8859-1?Q?Risto_Per=E4nen?=

Sami said:
Hello,

Is there an easy way to make script print text with differents colors to
screen (shell)?

I mean a script that can for example print lines in red if some error occurs
in executing
some information..

--SV

----Thanks in advance.
If you're using python at X, best advice I canv give is Text-widget at
Tkinter and RTFM (sorry couldn't resist temptation :) . Otherwise you
probably have to fiddle with curses-library (unix-only).

Best way to gather information of execution is to open log-file, code
couple of monkeys and let them crack system as much as possible. This is
only my opinion. Coders are blind to their mistakes even at testing.
 
M

Michael Peuser

Risto Peränen said:
....
If you're using python at X, best advice I canv give is Text-widget at
Tkinter and RTFM (sorry couldn't resist temptation :) . Otherwise you
probably have to fiddle with curses-library (unix-only).

Some month's ago Adam Vandenberg released some alpha curses for Windows

http://flangy.com/dev/python/curses/

I worked with my Win2000 but is only a partial implementation. It has some
color support that migth suffice for the request of the OP.

Kindly
Michael P
 
F

Fernando Perez

Sami said:
Hello,

Is there an easy way to make script print text with differents colors to
screen (shell)?

I mean a script that can for example print lines in red if some error occurs
in executing
some information..

IPython (http://ipython.scipy.org) supports coloring for its own purposes, and
comes with a module for this. You can simply import this module and use it for
your programs. Besides, you may like ipython itself ;)

Cheers,

f.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,097
Messages
2,570,622
Members
47,235
Latest member
LuisaHamle

Latest Threads

Top