Information:
System version : Windows 10 64-bit
Python version : Python 3.6.0 :: Anaconda 4.3.1 (64-bit)
Python version : Python 3.6.0 :: Anaconda 4.3.1 (64-bit)
Code:
import ast
str1 = "{'a' : 1, 'b' : 2}"
dict1 = ast.literal_eval(str1)
print(dict1)
Result:
{'a': 1, 'b': 2}
沒有留言:
張貼留言