Malformed String error - Python - converting string repr. of dictionary
问题 When I do ast.literal_eval() , I get ValueError: malformed string for the line below z = ast.literal_eval(a) . Why is this not working? (Pls. note - "something" in the line below has 4 or more namedtuples) for thing in something: a = thing._asdict() z = ast.literal_eval(a) print z If I do a simple print a , I get OrderedDict([('a', 0.0), ('b', 0.0), ('c', 0.0), ('d', 100.0)]) Without ast.literal_eval(a) , when I try to use "a" as a dictionary, it raises AttributeError: 'str' object has no