The fundamentals...
mspiggie at my-deja.com
mspiggie at my-deja.com
Fri Jan 26 11:54:38 EST 2001
In article <mailman.980380532.28633.python-list at python.org>,
Neil Schemenauer <nas at arctrix.com> wrote:
> Its probably clearer use string.replace. Using ?!ng's excellent
> pydoc command:
>
> $ pydoc string.replace
>
> Python Library Documentation: function replace in 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.
>
> So you can do:
>
> boo = string.replace(". ", "\n")
>
> In Python 2.0 or later you can use string methods:
>
> boo = boo.replace(". ", "\n")
>
> Cheers,
>
> Neil
>
>
I have been trying to find a way to use replace() to perform more than
one replacement within a given file. For instance, suppose I needed to
replace ". " with "\n", but also need to replace "!" with "exclamation"
and "?" with "question". I have tried several approaches to this, but
none of my neophyte ideas have produced satisfying results.
Rob
Sent via Deja.com
http://www.deja.com/
More information about the Python-list
mailing list