我有一个如下所示的数组:[" string",int,[]]但是当我尝试增加int时Python会给我一个错误。 (顺便说一句,我是python的新手,所以这可能是一个简单的问题)
TypeError:' int'对象不可迭代
以下是我的代码中有问题的部分:
for line in responseid_container:
if line[0] is log.id_resp_address:
ipFound = True
#--- this line is where I get an exception ---
responseid_container[1] += 1
responseid_container[2].append = log.id_resp_address
(例如,对于responseid_container = [' 54.192.11.194',1,[0]])
我试图在很多地方寻找答案,例如:here,here,here,here等等...我希望它不是一个重复的答案,但我确实尝试找到它是否: - )
如果需要,这是我的完整代码
from reader import fullLog
class counters:
local_logs = []
arrange_by_response_id = []
def __init__(self , fulllog):
self.local_logs = fulllog
def arrangebyresonseid(self):
responseid_container = [[" " , 0 , []]]
ipFound = False
counter = 0
for log in self.local_logs.oopList:
for line in responseid_container:
if line[0] is log.id_resp_address:
ipFound = True
responseid_container[1] += 1
responseid_container[2].append = log.id_resp_address
if not ipFound:
ipFound = False
responseid_container.append([log.id_resp_address , 1 , [counter]])
counter += 1
答案 0 :(得分:1)
我在本声明中检查了您的代码: -
responseid_container[1] += 1
将此行转换为: -
responseid_container[0][1] += 1
仔细检查: -
responseid_container = [
0 => [
0 => " " , 1 => 0 , 2 => []
]
]