I want to replace "'" with "\'" inside the word "O'Fallon".
But when I use the following code:
City="O'Fallon"
City.replace("'","\'")
I get "O'Fallon" as the output and when use this code:
City="O'Fallon"
City.replace("'","\\'")
I get "O\\'Fallon" as the output. Could you please help me on this?
print City.replace("'", "\\'").repr(City)orpipes.quote(City)(orshlex.quote()on Python >= 3.3), depending on what environment you want to escape your string for.