print color strings?

Donn Cave donn at u.washington.edu
Thu Jul 1 17:55:55 EDT 1999


"Fred L. Drake" <fdrake at cnri.reston.va.us> writes:
|Gerrit Holl writes:
|> is there an easy way to print color strings in python?
|> 
|> A function like printcolor('brightyellow', 'red', 'spam'), that finds
|> out on what kind of terminal you are and prints it to stdout?
|
| Gerrit,
|   If you're doing this on Unix, take a look at the ncurses library;
| there's a Python interface to that.  (I think Oliver Andrich did it;
| searching DejaNews should find it fairly quickly since this keeps
| coming up.)
|   The standard curses module will be documented in the next release of 
| the Library Reference.

And if that doesn't work, probably your termcap or terminfo definitions
lack the necessary information about color escape sequences.  That's a
widespread problem.

The color escape sequences that have worked for me on a couple of terminal
types have been of the form <ESC>[32m, where 32 is a number from 30 to 37.
I use only 31 to 36.  30 and 37 are more or less black and white, but the
details vary, so I switch from color to non-color with <ESC>[m instead of
trying to sort out the details of black and white vs. background and
foreground.

Of course these are terminal specific escape sequences.  They're evil and
you must not use them, especially if you have a choice.

	Donn Cave, University Computing Services, University of Washington
	donn at u.washington.edu







More information about the Python-list mailing list