472,139 Members | 1,487 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,139 software developers and data experts.

Coloring print lines

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.
Jul 18 '05 #1
5 20360
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
--
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself?
Jul 18 '05 #2
Sami Viitanen wrote:
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.

Jul 18 '05 #3

"Risto Peränen" <no@more.spam.plea.se> schrieb im Newsbeitrag
news:bi**********@mordred.cc.jyu.fi...
Sami Viitanen wrote:
Hello,

Is there an easy way to make script print text with differents colors to
screen (shell)?
.... 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

Jul 18 '05 #4
| Is there an easy way to make script print text
| with different colors to screen (shell)?
| ...

Sami ...

I have a couple of small examples for printing
colorized strings via Ansi escape sequences
from Python under Windows ...

http://fastq.com/~sckitching/Python/ansi_strings.zip

--
Cousin Stanley
Human Being
Phoenix, Arizona
Jul 18 '05 #5
Sami Viitanen wrote:
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.
Jul 18 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Wow | last post: by
5 posts views Thread by Tom Louchbaum | last post: by
6 posts views Thread by Melissa | last post: by
12 posts views Thread by rajash | last post: by
3 posts views Thread by lilly07 | last post: by
3 posts views Thread by Anja Friedrich | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.