字典(dict) 转为字符串(string)
for key, value in sample_dic.items(): print "\"%s\":\"%s\"" % (key, value)
字符串(string)转为字典(dict)
>>> a = "{'a': 'hi', 'b': 'there'}" >>> b = eval(a) >>> b {'a': 'hi', 'b': 'there'} >>> exec ("c=" + a) >>> c {'a': 'hi', 'b': 'there'}
本文转自 Art_Hero 51CTO博客,原文链接:http://blog.51cto.com/curran/1608622,如需转载请自行联系原作者