How to replace single quotes with double quotes in python?

Asked

Viewed 705 times

2

I used the function replace to replace single quotes from a field in csv with double quotes, but in output the value comes out with escape character , it is this character remains when clicking to hdts.

Codeline:

txt_situ_mens = linha_csv[11].replace("/'", "/'")

Archive at the entrance:

{'delivered': '2018-09-15 00:35:00+0000', 'read': '2018-09-15 00:35:00+0000', 'received': '2018-09-15 00:33:43+0000'}

Archive in the Saida:

{\"delivered\": \"2018-09-15 00:35:00+0000\", \"read\": \"2018-09-15 00:35:00+0000\", \"received\": \"2018-09-15 00:33:43+0000\"}

How would you like the file to come out: {"Delivered": '2018-09-15 00:35:00+0000", "read": "2018-09-15 00:35:00+0000", "Received": "2018-09-15 00:33:43+0000"}

  • 1

    I didn’t understand your question could elaborate better?

  • 1

    Yes, because what you’re exhibiting is a string and if the quote was not escaped it would break the syntax of the language: "{"delivered": "2018-12-11", ...}"

  • What would "load to hdts"?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.