Search code examples
pythonstringreplaceapostrophequotation-marks

Replace Apostrophe with Quote mark in Python


I'm trying to write a program which compares specific parameters of INI Files. The problem is that there are some Strings in those files which are marked with an apostrophe and some other which are marked with quote marks.

What I am trying to do is to convert either every quotation mark to an apostrophe or to convert every apostrophe to a quotation mark.

I've tried it with replace but the string won't change in either way. Here is a simple test I made to See if it works, the string is part of an INI File:

e = "'03:SUN/05:00:00'"
e.replace("'",'"')
print (e)

But the console output is just the same string:

'03:SUN/05:00:00'

Is there another way to replace them?


Solution

  • replace doesn't change the string you are working on. It returns a string with the replacement done

    e = e.replace("'", '"')