python3版本UnicodeDecodeError: ascii codec can t decode byte 0xe2 in position 0 ordinal not in rang

当用python3读取文件时

 with open(input_file) as f:

for line in f:
  File "/usr/lib/python3.5/encodings/ascii.py", line 26, in decode
    return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe5 in position 0: ordinal not in range(128)

 

需改为 encoding="utf-8",即可解决

 with open(input_file,encoding="utf-8") as f:

你可能感兴趣的:(python3版本UnicodeDecodeError: ascii codec can t decode byte 0xe2 in position 0 ordinal not in rang)