Python2 的字符编码的坑

  1. 设置相应的默认编码为utf8;
  2. 读文件拿到str类型:str -> decode(‘utf8’) -> unicode
  3. 程序处理:用unicode
  4. 写文件:unicode -> encode(‘utf8’) -> str,用str类型写入文件

当然前提是文件都是utf8格式的啦,包括源文件和读写的数据文件。

最后,python3真好

更多

猜你喜欢

转载自blog.csdn.net/jason_cuijiahui/article/details/80010199