String Replacement

Daniel Dittmar daniel at dittmar.net
Sat Aug 2 00:14:51 CEST 2003


Fazer wrote:
> import string
> string.replace(DataFromDatabase, "\n", "<br>")
> 
> Unfortunately, it doesn't work.  

You'll probably want

import sys
import string
sys.out.write (string.replace(DataFromDatabase, "\n", "<br>"))

or for Python 2.x

import sys
sys.out.write (DataFromDatabase.replace ("\n", "<br>"))


Seeing the result of an expression without print works only at the 
interactivew prompt:
 >>> string.replace ("abc\nde", '\n', '<br>')
'abc<br>de'
 >>> print string.replace ("abc\nde", '\n', '<br>')
abc<br>de

Daniel





More information about the Python-list mailing list