Text Formating in Python

Emile van Sebille emile at fenx.com
Sun Aug 26 01:03:28 EDT 2001


from random import randrange as rand
def formatWithColor(i):
    color = '#000000'
    if i < 0: color = '#ff0000'
    if i > 0: color = '#008000'
    return '<font color=%s>%8.2f' % (color, i)
print "<BR>".join([formatWithColor(rand(-99,99)) for i in range(10)])

Add seasonings to taste...

--

Emile van Sebille
emile at fenx.com

---------
"Lee Hulbert" <lhulbert at hotmail.com> wrote in message
news:1cdcc92f.0108252020.20aaa02e at posting.google.com...
> 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.
>
> Thank You,
>
> Lee




More information about the Python-list mailing list