繁体   English   中英

我该怎么办?(类型错误)

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM