If I use literal_eval on some strings to get a dictionary, it works fine:
import ast string = '{123: True, 456: False}' In: ast.literal_eval(string) Out: {123: True, 456: False} But if the string has a string within it, I get an error:
string = '{123: Foo, 456: Bar}' In: ast.literal_eval(string) Out: ValueError: malformed node or string: <_ast.Name object at 0x7f7d5faae9e8> How can I keep strings in the second literal_eval?
{123: Foo, 456: Bar},FooandBarare python objects. Did you mean{123: "Foo", 456: "Bar"}?