Tags: colored, file, programming, python, text, towrite

Colored text

On Programmer » Python

4,312 words with 6 Comments; publish: Sun, 27 Apr 2008 23:24:00 GMT; (20062.50, « »)

Hello,

Can some one tell me how do I get colored text. Say when I want to

write something in a text file , how do I get it colored.

All Comments

Leave a comment...

  • 6 Comments
    • On Aug 12, 10:05 pm, Rohan <vodela....python.todaysummary.com.gmail.com> wrote:

      > Hello,

      > Can some one tell me how do I get colored text. Say when I want to

      > write something in a text file , how do I get it colored.

      Plain text files don't have color. You could output in html ...

      #1; Sun, 27 Apr 2008 23:25:00 GMT
    • On Aug 12, 10:01 pm, ianar=E9 <ian....python.todaysummary.com.gmail.com> wrote:

      > On Aug 12, 10:05 pm, Rohan <vodela....python.todaysummary.com.gmail.com> wrote:

      >

      > Plain text files don't have color. You could output in html ...

      Oh ok what about a csv file, I know its also a text file but I want

      the color to be say blue in an excel sheet.

      #2; Sun, 27 Apr 2008 23:26:00 GMT
    • On Aug 12, 2007, at 7:05 PM, Rohan wrote:

      > Can some one tell me how do I get colored text. Say when I want to

      > write something in a text file , how do I get it colored.

      You can use ANSI escape codes -- http://en.wikipedia.org/wiki/=20

      ANSI_escape_code:

      colorCodes =3D [

      "\033[0mAll attributes off\033[0m",

      "\033[1mBold\033[0m",

      "\033[4mUnderline\033[0m",

      "\033[5mBlink\033[0m",

      "\033[8mHide\033[0m",

      "\033[30mBlack\033[0m",

      "\033[31mRed\033[0m",

      "\033[32mGreen\033[0m",

      "\033[33mYellow\033[0m",

      "\033[34mBlue\033[0m",

      "\033[35mMagenta\033[0m",

      "\033[36mCyan\033[0m",

      "\033[37mWhite\033[0m",

      "\033[40m\033[37mBlack Background\033[0m",

      "\033[41mRed Background\033[0m",

      "\033[42mGreen Background\033[0m",

      "\033[43mYellow Background\033[0m",

      "\033[44mBlue Background\033[0m",

      "\033[45mMagenta Background\033[0m",

      "\033[46mCyan Background\033[0m",

      "\033[47mWhite Background\033[0m"

      ]

      for i in colorCodes:

      print i

      hth,

      Michael

      --

      "I would rather use Java than Perl. And I'd rather be eaten by a =20

      crocodile than use Java." =97 Trouser

      #3; Sun, 27 Apr 2008 23:27:00 GMT
    • On Aug 13, 1:50 am, Rohan <vodela....python.todaysummary.com.gmail.com> wrote:

      > On Aug 12, 10:01 pm, ianar=E9 <ian....python.todaysummary.com.gmail.com> wrote:

      >

      >

      >

      > Oh ok what about a csv file, I know its also a text file but I want

      > the color to be say blue in an excel sheet.

      CSV is also pretty much plain text. No support for formatting.

      You will need to write xls files. Personaly, I avoid proprietary file

      formats like the plague, but this may be what you're looking for:

      http://www.answermysearches.com/ind...ormatted-file-=

      right-in-python/122/

      #4; Sun, 27 Apr 2008 23:28:00 GMT
    • On 2007-08-13, Michael Bentley <michael.python.todaysummary.com.jedimindworks.com> wrote:

      > On Aug 12, 2007, at 7:05 PM, Rohan wrote:

      > You can use ANSI escape codes -- http://en.wikipedia.org/wiki/

      > ANSI_escape_code:

      Unfortunately, most versions of Windows of the last 7 years

      (2000, XP, probably Vista) don't support ANSI escape codes well

      enough to work with Python.

      Neil Cerutti

      We have to play hard for the full 40 minutes. 48? Oh, that's right. --Mikki

      Moore

      #5; Sun, 27 Apr 2008 23:29:00 GMT
    • On Aug 13, 10:37 am, Neil Cerutti <horp....python.todaysummary.com.yahoo.com> wrote:

      > On 2007-08-13, Michael Bentley <mich....python.todaysummary.com.jedimindworks.com> wrote:

      >

      >

      >

      > Unfortunately, most versions of Windows of the last 7 years

      > (2000, XP, probably Vista) don't support ANSI escape codes well

      > enough to work with Python.

      > --

      > Neil Cerutti

      > We have to play hard for the full 40 minutes. 48? Oh, that's right. --Mikk

      i

      > Moore

      Check out these recipes:

      http://aspn.activestate.com/ASPN/Co...n/Recipe/475116

      http://aspn.activestate.com/ASPN/Co...n/Recipe/496901

      #6; Sun, 27 Apr 2008 23:31:00 GMT