Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to force a dictionary to be written with " " instead of ' '

So I am working on a project in which I build an ongoing dictionary for kennings (its for a norse mythology course). The problem I run into is on occasion a kenning has an apostrophe in it. For example the kenning "wolf’s joint" which has the definition "joint" gets written to the dictionary as {"wolf’s wrist": ‘joint’}, this would be fine if the json.loads() function didn’t through up an error because the key has "" and the value has ”. I was wondering if there is a way to force a dict to be written always with the "" instead of ”.

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You can try json.dumps:

>>> print(json.dumps({"wolf's wrist": 'joint'}))
{"wolf's wrist": "joint"}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading