python写入文件编码报错

python学习网 2017-11-04 00:30:01

decode的作用是将其他编码的字符串转换成unicode编码,如str1.decode('gb2312'),表示将gb2312编码的字符串str1转换成unicode编码。

encode的作用是将unicode编码转换成其他编码的字符串,如str2.encode('gb2312'),表示将unicode编码的字符串str2转换成gb2312编码。

 

后台处理时用decode,将数据写入文件中时用encode

 

阅读(829) 评论(0)