363,924 Members | 2585 Browsing Online
Community for Developers & IT Professionals
Bytes IT Community

Output in color

Bradford Powers
P: n/a
Bradford Powers
I'm curious how I can make Python print text in color.


Jul 18 '05 #1
Share this Question
Share on Google+
2 Replies


Peter Hansen
P: n/a
Peter Hansen
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
Jul 18 '05 #2

Alex Martelli
P: n/a
Alex Martelli
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

Jul 18 '05 #3

Post your reply

Help answer this question



Didn't find the answer to your Python question?

You can also browse similar questions: Python