By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,036 Members | 1,963 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,036 IT Pros & Developers. It's quick & easy.

Colored text

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

Aug 13 '07 #1
Share this Question
Share on Google+
7 Replies


P: n/a
On Aug 12, 10:05 pm, Rohan <vodela....@gmail.comwrote:
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 ...

Aug 13 '07 #2

P: n/a
On Aug 12, 10:01 pm, ianaré <ian...@gmail.comwrote:
On Aug 12, 10:05 pm, Rohan <vodela....@gmail.comwrote:
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 ...
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.

Aug 13 '07 #3

P: n/a

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/
ANSI_escape_code:

colorCodes = [
"\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
crocodile than use Java." — Trouser
Aug 13 '07 #4

P: n/a
On Aug 13, 1:50 am, Rohan <vodela....@gmail.comwrote:
On Aug 12, 10:01 pm, ianaré <ian...@gmail.comwrote:
On Aug 12, 10:05 pm, Rohan <vodela....@gmail.comwrote:
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 ...

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/inde...in-python/122/

Aug 13 '07 #5

P: n/a
On 2007-08-13, Michael Bentley <mi*****@jedimindworks.comwrote:
>
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/
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
Aug 13 '07 #6

P: n/a
On Aug 13, 10:37 am, Neil Cerutti <horp...@yahoo.comwrote:
On 2007-08-13, Michael Bentley <mich...@jedimindworks.comwrote:
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/
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
Check out these recipes:
http://aspn.activestate.com/ASPN/Coo.../Recipe/475116
http://aspn.activestate.com/ASPN/Coo.../Recipe/496901

Aug 13 '07 #7

P: n/a
On 2007-08-13, Rohan <vo********@gmail.comwrote:
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.
The PyRTF module supports colored text, and RTF is portable
(mostly).

--
Grant Edwards grante Yow! What I want to find
at out is -- do parrots know
visi.com much about Astro-Turf?
Aug 15 '07 #8

This discussion thread is closed

Replies have been disabled for this discussion.