Output in color

Discussion in 'Python' started by Peter Hansen, Sep 4, 2003.

  1. Peter Hansen

    Peter Hansen Guest

    Bradford Powers wrote:
    >
    > I'm curious how I can make Python print text in 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
     
    Peter Hansen, Sep 4, 2003
    #1
    1. Advertising

  2. I'm curious how I can make Python print text in color.
     
    Bradford Powers, Sep 5, 2003
    #2
    1. Advertising

  3. Bradford Powers wrote:

    > I'm curious how I can make Python print text in 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
     
    Alex Martelli, Sep 5, 2003
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. moondaddy
    Replies:
    3
    Views:
    38,333
    moondaddy
    Apr 28, 2004
  2. PJ6
    Replies:
    4
    Views:
    4,897
  3. Andrew Arace

    BGR Color to Java Color

    Andrew Arace, Sep 13, 2003, in forum: Java
    Replies:
    7
    Views:
    7,806
    Stephen Gilbert
    Sep 16, 2003
  4. Niels Dybdahl

    Color.white vs. Color.WHITE

    Niels Dybdahl, Oct 6, 2004, in forum: Java
    Replies:
    3
    Views:
    443
    Chris Smith
    Oct 6, 2004
  5. Kamaljeet Saini
    Replies:
    0
    Views:
    427
    Kamaljeet Saini
    Feb 13, 2009
Loading...

Share This Page