>>> path = 'name.txt'
>>> content = None
>>> with open(path, 'r') as file:
... content = file.readlines()
...
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
File "/mnt/lustre/share/miniconda3/lib/python3.6/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 163: ordinal not in range(128)
当我运行此代码读取包含中文字符的文件时,出现错误。该文件使用 UTF-8 保存。我的python版本是3.6.5。但它在python2.7中运行正常。
小怪兽爱吃肉
达令说
相关分类