类型错误:'int' 对象不可下标 python

时间:2021-02-08 19:51:54

标签: python list csv integer

我正在尝试使用 CSV 文件,使用最小值和最大值,按编号返回一系列 Pokemon,因此我想将数字更改为整数。到目前为止,如果我不将输入作为整数,我只能返回一个精确的 Pokemon。我的 CSV 有 801 行,poke[0] 是他们的编号,poke[1] 是他们的名字。

def number(list):
  newlist = []
  x = 0
  q2 = int(input("Minimum number? "))
  q3 = int(input("Maximum number? "))
  for poke in range(1,800):
    poke[0] = int(poke[0])
  for poke in list:
    if poke[0] >= q2 and poke[0] <= q3:
      newlist.append(poke[0] + " " + poke[1])
  for poke in newlist:
    print(newlist[x])
    x = x + 1

1 个答案:

答案 0 :(得分:1)

在第一个循环中,您将 poke 作为范围 1, 800 内的整数递增。此整数无法编入索引。