Connecting Tech Pros Worldwide Help | Site Map

Output in color

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 18th, 2005, 02:16 AM
Bradford Powers
Guest
 
Posts: n/a
Default Output in color

I'm curious how I can make Python print text in color.



  #2  
Old July 18th, 2005, 02:16 AM
Peter Hansen
Guest
 
Posts: n/a
Default 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
  #3  
Old July 18th, 2005, 02:17 AM
Alex Martelli
Guest
 
Posts: n/a
Default 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

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,662 network members.