-2

I have a dictionary that has apostrophes for the value and key in every entry. For instance one entry would look like this:

{'lat': '38.683959', 'lon': '-90.265198', 'accuracy': '3'}

I need to get rid of these apostrophes so I can write them into SQL. The single quotes cause an error when I try to write them. What is the best way to get rid of all of the apostrophes?

Thanks for your help!

Emac
  • 1,098
  • 3
  • 18
  • 37
  • 4
    Those apostrophes are there because its a string datatype. – Autonomous Jun 06 '18 at 21:13
  • Here is an answer. Can't mark as duplicate https://stackoverflow.com/questions/18283725/how-to-create-a-python-dictionary-with-double-quotes-as-default-quote-format – Jake Steele Jun 06 '18 at 21:15
  • 1
    Maybe you should show the code you are using to "write this into SQL". Your question is impossible to understand otherwise. – Daniel Roseman Jun 06 '18 at 21:20
  • 2
    There are no apostrophes in the dictionary, it contains strings. When you print a dictionary, it puts quotes around the strings, but they're not really in there. – Barmar Jun 06 '18 at 21:32
  • If you substitute into your prepared SQL query properly, the quotes shouldn't be put into it. – Barmar Jun 06 '18 at 21:33
  • 1
    Sounds like maybe you want to encode the dict as a string and write to a single database column? If that's the case, you should be able to find an existing answer in SO pretty easily. – dmulter Jun 06 '18 at 22:50
  • Thanks for those who left useful feedback. What dmulter said pointed me in the right direction. I needed to convert the dictionary to a single string, and I found my solution here: https://stackoverflow.com/questions/10472907/how-to-convert-dictionary-into-string – Emac Jun 07 '18 at 14:17

1 Answers1

0

Instead of leaving the question open, I wanted to answer it myself. One of the comments pointed me in the right direction that I needed to convert my dictionary to a string, and I found the solution to do that here:

How to convert dictionary into string

Emac
  • 1,098
  • 3
  • 18
  • 37