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