String Replacement

Raymond Hettinger vze4rx4y at verizon.net
Sat Aug 2 00:36:41 EDT 2003


"Tim Heaney" <theaney at cablespeed.com> wrote in message
news:87lluckewd.fsf at mrbun.watterson...
> faizan at jaredweb.com (Fazer) writes:
> >
> > This works:
> > print string.replace(str, "\n", "<br>")
> >
> > But I can't assign the result into a variable but only print it like
> > the code above.
>
> The return value is the string you want. So, rather than printing it,
> assign it to a variable. You can reuse str, if you like...
>
>   str = string.replace(str, "\n", "<br>")
>
> Note that since str is a string, you can invoke its replace method
>
>   str = str.replace("\n", "<br>")
>
> rather than the class method.
>
> I hope this helps,
>
> Tim

"str" is the name of the builtin string type.
So, it is inadvisable to re-use "str" as a
variable name.


Raymond Hettinger






More information about the Python-list mailing list