尝试在另一个内部运行函数时,接收“int”对象不是可下标的错误

2024-05-15 03:50:25 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图运行一个“作战模拟”程序,然后在每个用户回合上运行一系列子功能。 每个子函数都可以正常工作,但当我尝试运行整个精简时,我得到一个“int”对象是不可下标的错误。以下是受影响的功能:

def obter_posicao(u1):
    return u1[0]
def ordenar_unidades(tupuni):
    lista_p = []
    uni_ordenadas = []
    for u1 in tupuni:
        lista_p.append([obter_posicao(u1), u1])
    uni_em_order_per_p = sorted(lista_p, key=lambda x: (
        obter_pos_y(x[0]), obter_pos_x(x[0])))
    for p in range(len(lista_p)):
        uni_ordenadas.append(uni_em_order_per_p[p][1])
    return uni_ordenadas
def mover_unidade(m1, u1, p):
unit = list(u1)
    unit[0] = p
    u2 = tuple(unit)
    c = 0
    b = -1
    for u in m1[2]:
        if u1 == u:
            e1 = m1[2][:b] + u2 + m1[2][c:]
            e2 = ordenar_unidades(e1)
            m2 = (m1[0], m1[1], e2, m1[3])
            return m2
        b += 1
        c += 1
    for u in m1[3]:
        if u1 == u:
            e1 = m1[3][:b] + u2 + m1[3][c:]
            e2 = ordenar_unidades(e1)
            m2 = (m1[0], m1[1], m1[2], e2)
            return m2
        b += 1
        c += 1

我得到以下错误:

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "<input>", line 10, in mover_unidade
  File "<input>", line 94, in ordenar_unidades
  File "<input>", line 45, in obter_posicao
TypeError: 'int' object is not subscriptable

Tags: inforinputreturnfileuniobterlista

热门问题