Python turns strings into dictionaries except for json.loads ()

how to change strings into dictionaries in python except json.loads

see eval on the Internet, but this always reports an error

so this eval is not good?

Mar.31,2021

you can use this:


Python 2.6.3 (r263rc1:75186, Oct  2 2009, 20:40:30) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import ast
>>> ast.literal_eval("{'a':'a','b':0}")
{'a': 'a', 'b': 0}
>>>

by the way, eval is OK, but ast.literal_eval is more efficient and secure.

Menu