How to replace single quotes (')
with '
in python?
Need to convert from
"{'fr': '', 'en': 'Title Edit 02'}"
to
"{'fr': '', 'en': 'Changed'}"
Advertisement
Answer
Try the following code:
s = "{'fr': '', 'en': 'Title Edit 02'}" s= s.replace("'","\'").strip("\'") print(s) # Or Do What you need with s
Output: {'fr': '', 'en': 'Title Edit 02'}
Explanation: Replace all ‘ with ‘. strip() can be omitted, just a fail safe.