1.eval(): 把字符串数据类型转换成原本数据类型
例如: 数据从 Excel 中拿出来是: 数值的格式不变, 其他的格式都转成了字符串. 要保持原有数据格式不变, 需要用到 eval()
- S = 'True'
- print(eval(S),type(eval(S))) #bool
- s1 = '18'
- print(eval(s1),type(eval(s1))) #int
- s2 = '{"age":18}'
- print(eval(s2),type(eval(s2))) #dict
2.JSON.dumps(): 把 python 对象 (诸如 dict/list/tuple/string 等数据结构) 转换为字符串(编码)
3.JSON.loads(): 把 JSON 化的字符串转换成对应的 python 对象(诸如 dict/list/tuple/string 等数据结构)(解码)
4.JSON.dump() 和 JSON.load() 用于处理文件, 来编码和解码 JSON 数据
来源: http://www.bubuko.com/infodetail-3363238.html