我有一个函数将数据附加到数组中:
def _get_state(self, cr, uid, context=None):
idemployee = _default_employee(self, cr, uid, context=None)
sql = " SELECT C.id AS id, C.sequence, C.name \
FROM wf_group_member A \
LEFT JOIN wf_group B ON B.id = A.group_id \
LEFT JOIN wf_process BB ON BB.id = B.process_id\
LEFT JOIN wf_state C ON C.group_id = B.id \
LEFT JOIN hr_employee D ON D.id = A.member_id \
WHERE LOWER(code) = 'ca' AND member_id = %s ORDER BY sequence "
res = []
cr.execute(sql, [(idemployee)])
ardata = cr.fetchall()
for data in ardata:
res.append((data[1], data[2]))
return res
然后我尝试获取最大数组索引的值:
def _get_maxstate(self, cr, uid, context=None):
res = []
arr_state = _get_state(self, cr, uid, context)
states = len(arr_state) - 1
res = arr_state[0][states]
return res
但是当我在操作按钮中调用_get_maxstate时,会引发错误:
res = arr_state[0][states]
IndexError: tuple index out of range
我的代码出了什么问题,请帮帮我
答案 0 :(得分:1)
states
是arr_state
的最后一个元素的索引。但是,您不会将arr_state
与states
编入索引,而是使用0
对其进行索引,然后使用states
将结果编入索引。看起来您可能只想反过来索引,即arr_state[states][0]
。