|
Adrien Plisson
rien at yeepa.org
Thu Jun 5 23:08:14 EST 2003
Irene Ponti wrote:
> Now in php exist a standard function that add slashes
> in front of ' or " in a variable and another that
> remove slashes.
>
>Is there in python a function like this?
Hi Irene,
you have 2 choices:
- string objects in python offers a replace() member.
so you can write:
query = """a string with 'quotes' and "doublequotes" """
new_query = query.replace('"', '\\"')
- the re module allows for regular expression searching and replacement
but this mail is far too short too explain regular expression.
just have a look at the python manuals (chapter 4.2 of the library
reference).
Just beware that '\' is a special character inside python string:
"\\'" is totally different from "\'". the first form describe a
backslash preceding a single quote character, the second describe a
string which only contains a single quote. idem for double quotes.
> Thank you.
you're welcome...
--
rien
|