String Replacement
Bengt Richter
bokr at oz.net
Fri Aug 1 18:23:43 EDT 2003
On 1 Aug 2003 15:00:47 -0700, faizan at jaredweb.com (Fazer) wrote:
>Hello,
>
>As some of you might know, I am new to Python. I was finally
>successful in using MySQLdb for Python to query the datbase and get a
>few results from the query.
>
>The results will be displayed as HTML and I am sort of confuse din
>using the string modules and its functions/modules to replace the \n
>with <br>. I import the string module and I am not soo sure on how to
>do the replacing.
>
>Here's how my code sort of likes:
>
>import string
print repr(DataFromDatabase) # do this to check what you are operating on
>string.replace(DataFromDatabase, "\n", "<br>")
print repr(string.replace(DataFromDatabase, "\n", "<br>")) # to see result
>>> import string
>>> help(string.replace)
Help on function replace in module string:
replace(s, old, new, maxsplit=-1)
replace (str, old, new[, maxsplit]) -> string
Return a copy of string str with all occurrences of substring
old replaced by new. If the optional argument maxsplit is
given, only the first maxsplit occurrences are replaced.
>>Unfortunately, it doesn't work.
You are throwing away the result ;-)
Regards,
Bengt Richter
More information about the Python-list
mailing list