Skip to content
Advertisement

How to get a list with dict entries from text file?

I saved a list with dict entries to a txt file.

When I try to read it back into python with

JavaScript

I just get a huge string which looks like this:

JavaScript

What’s an easy way to get this back in the original format?

Advertisement

Answer

What you want is “Convert a String to JSON”, but the type of your file content is not JSON, because the key in JSON should be enclosed in double quotes.

The correct content should like this:

JavaScript

then we can convert it to original format:

JavaScript

Please make sure whether your key in str is enclosed or not, if not, we can make it enclosed by:

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement