string to dict - KerwinKoo/KerwinKoo.github.io GitHub Wiki

python 将一个字符串(string)转为字典(dict)

>>> a = "{'a': 'hi', 'b': 'there'}"
>>> b = eval(a)
>>> b
{'a': 'hi', 'b': 'there'}
>>> exec ("c=" + a)
>>> c
{'a': 'hi', 'b': 'there'}
>>>
⚠️ **GitHub.com Fallback** ⚠️