Text Formating in Python

Peter Hansen peter at engcorp.com
Sun Aug 26 17:24:45 CEST 2001


Emile van Sebille wrote:
> 
> 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)
or
      return '<font color="%s">%8.2f</font>' % (color, i)

> print "<BR>".join([formatWithColor(rand(-99,99)) for i in range(10)])
or
  print "<br/>".join( .....

(Closer to being compatible with XHTML. :)



More information about the Python-list mailing list