![](/img/trans.png)
[英]TypeError: 'int' object is not subscriptable. now what should i do?
[英]What should I do?(TypeError)
import re
ffail = ""
with open("regex_sum_340933.txt", "r" , "UTF-8") as some_file:
ffail = some_file.read()
count = 0
match = re.findall('[0-9]+', ffail)
for II in match:
number = int(II)
count = count + number
print(count)
这段代码给了我这个错误: with open("regex_sum_340933.txt", "r", "UTF-8") as some_file: TypeError: an integer is required (got type str)
open
的第三个参数是buffering
(请参阅文档),而不是encoding
,因此您需要将encoding
作为关键字参数传递。 另外,最好使用"utf8"
。
with open("regex_sum_340933.txt", "r" , encoding="utf8") as some_file:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.