Connecting Tech Pros Worldwide Forums | Help | Site Map

Output in color

Bradford Powers
Guest
 
Posts: n/a
#1: Jul 18 '05
I'm curious how I can make Python print text in color.



Peter Hansen
Guest
 
Posts: n/a
#2: Jul 18 '05

re: Output in color


Bradford Powers wrote:[color=blue]
>
> I'm curious how I can make Python print text in color.[/color]

Begin by specifying the platform on which you want this to work,
and other possibly relevant details such as whether this is a
console program or one with a GUI (presumably not), and maybe
some other details I can't think of right now.

Also you might check the archives of this newsgroup at
groups.google.com. This sort of question comes up fairly
often. Might even be a FAQ at this point (see www.python.org).

-Peter
Alex Martelli
Guest
 
Posts: n/a
#3: Jul 18 '05

re: Output in color


Bradford Powers wrote:
[color=blue]
> I'm curious how I can make Python print text in color.[/color]

That depends strictly on your printer. With my hp LaserJet 1200,
no way -- not even Python's power can overcome the hardware's
limitations in this regard... it's a black-and-white printer and
that's all there is to it! If I did have a color printer, then
I would have Python produce the appropriate postscript code, or
"escape-sequences" in whatever printer-specific language a given
printer requires to have it output color text (or, depending on my
operating system, printer driver, filters, etc, I might have to
send appropriate "escape-sequences" or whatever to the DRIVER in
order to convince it to drive the printer appropriately).

Much the same holds if you're using "printing" in the vague
sense in which Python itself uses it in the keyword "print"
(which I detest and consider a wart, albeit shared by such
diverse languages as Python, Perl, C, Fortran, etc): it all
depends on what device (physical hardware one, or one in some
part simulated by software) you're outputting to.

For example,

print '\033[1;31mciao!'

will set all text emitted henceforward to red _IF_ the
terminal (or emulator thereof) on which the text is being
written is ANSI compliant.


Alex

Closed Thread