Coloring print lines

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sami Viitanen

    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.


  • Sybren Stuvel

    #2
    Re: Coloring print lines

    Sami Viitanen enlightened us with:[color=blue]
    > Is there an easy way to make script print text with differents colors to
    > screen (shell)?[/color]

    Sure, just use ANSI codes.
    [color=blue]
    > I mean a script that can for example print lines in red if some
    > error occurs in executing some information..[/color]

    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?

    Comment

    • Risto Peränen

      #3
      Re: Coloring print lines

      Sami Viitanen wrote:[color=blue]
      > 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.
      >
      >[/color]
      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.

      Comment

      • Michael Peuser

        #4
        Re: Coloring print lines


        "Risto Peränen" <no@more.spam.p lea.se> schrieb im Newsbeitrag
        news:bid63i$oj9 $1@mordred.cc.j yu.fi...[color=blue]
        > Sami Viitanen wrote:[color=green]
        > > Hello,
        > >
        > > Is there an easy way to make script print text with differents colors to
        > > screen (shell)?[/color][/color]
        ....[color=blue]
        > 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).[/color]

        Some month's ago Adam Vandenberg released some alpha curses for Windows



        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



        Comment

        • Cousin Stanley

          #5
          Re: Coloring print lines

          | 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 ...



          --
          Cousin Stanley
          Human Being
          Phoenix, Arizona


          Comment

          • Fernando Perez

            #6
            Re: Coloring print lines

            Sami Viitanen wrote:
            [color=blue]
            > 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..[/color]

            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.

            Comment

            Working...