Python编码,解码问题

1.打开中文 txt 文件,报错:‘gbk’................:

以二进制打开

open("threekingdoms.txt", "rb").read() 读出来了
open("threekingdoms.txt", "r", encoding='utf-8',errors='ignore').read() 报错

 

 

2.打开中文出现乱码:

encodeing = 'gbk'

 

 

3.decode()

http://www.runoob.com/python/att-string-decode.html

      decode('ascii','igore') 解码遇到 ascii 是,忽略

猜你喜欢

转载自blog.csdn.net/zjkpy_5/article/details/86819229