【发布时间】:2020-05-13 10:32:51
【问题描述】:
我正在学习关于 py4e 的 python 课程,几乎完成了,但第 11 章似乎不可能,因为它每次都会给我错误。
错误:
line 4, in <module>
lines = ffail.read()
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/codecs.py", line 322, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd1 in position 8: invalid continuation byte
代码:
import re
ffail = open('regex_sum_340933.txt')
lines = ffail.read()
count = 0
match = re.findall('[0-9]+', lines)
for II in match:
number = int(II)
count = count + number
print(count)
【问题讨论】:
-
可以把数据放到txt文件里吗
标签: python-3.x file