python中,字符串和字典相互转换如下:
字符串转换为字典:
str_test = “{‘a’: 1, ‘b’: 2}”
dict_test = eval(str)
print dict_test
字典转换为字符串:
dict_test = {‘a’: 1, ‘b’: 2}
str_test = str(dict)
print str_test
python中,字符串和字典相互转换如下:
字符串转换为字典:
str_test = “{‘a’: 1, ‘b’: 2}”
dict_test = eval(str)
print dict_test
字典转换为字符串:
dict_test = {‘a’: 1, ‘b’: 2}
str_test = str(dict)
print str_test