Text Formating in Python

Peter Hansen peter at engcorp.com
Sun Aug 26 08:06:24 CEST 2001


Lee Hulbert wrote:
> 
> Is there a simple way to format a text string before printing to the
> screen?
> 
> Specifically, I have a list of 80 numbers, and I want to print the
> list, with each number a different color if it is positive, negative,
> or 0.

This is a platform-dependent issue.  You need to specify which 
platform you are using (operating system? windowed or console? etc.)
before anyone can answer this with any certainty.

However, in general you could consider changing the color of output
to be something that follows this general pattern:

 control-sequence1 actual-output control-sequence2

The first sequence changes the color to the one you want for the
output, then comes the output itself, then comes another 
sequence to return the color to the normal one.  Optionally you
can skip the latter until the very end, if you are going to output
color control sequences before _every_ number.

With this in mind, it wouldn't be at all difficult to write
a routine which colorizes numeric output based on a simple
analysis of its value.

But I think you are not asking that question, but rather
you are on a specific platform and just want to know how
to control the output color... ?

-- 
----------------------
Peter Hansen, P.Eng.
peter at engcorp.com



More information about the Python-list mailing list