python中字符串和字典类型互相转换

来源:互联网 发布:企业展示型网站源码 编辑:程序博客网 时间:2024/06/11 05:51

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


阅读全文
0 0
原创粉丝点击