Writing linux term color codes to a file

Andrei Kulakov ak at silmarill.org
Wed Sep 18 03:09:37 CEST 2002


I ran into a bit of a problem here.. I'm making a small app that
visually creates bash prompts (just for fun of it), and at one point
it has to write the prompt to .profile, optionally with linux terminal
color codes, like \[044;\]m or something like that (you know what I'm
talking about). They don't come out right *in* the file. I tested the
simple case where I'd have a few such codes in a string in python
prompt and I'd look at it and it looks fine, but as soon as I write it
out to a file and look at the file, it's "cooked".

I hope you know what I mean, if anyone wants I can post direct pastes.

Looks like write() does some sort of processing on the text; is there
any way to turn that off?

Thanks a lot,

 - Andrei

More information about the Python-list mailing list