TypeError: 'int' object is not subscriptable using xlrd

TypeError: 'int' object is not subscriptable using xlrd

我想使用 xlrd 从 excel sheet 中读取数据。我想遍历 excel 中的特定单元格,如果我没有找到数字“1”,我想将 +1 添加到行号并重新开始。我的问题是,当我在 for 循环中指定单元格时,我得到一个 TypeError:'int' object is not subscriptable.

import xlrd

Excelsheet1 = "info_2020.xlsx" 
Book1 = xlrd.open_workbook(Excelsheet1) 
first_sheet = Book1.sheet_by_index(9)

row_num = 1

for look_for_one in first_sheet.row_values(row_num[12]):
        if look_for_one == 1:
            print(first_sheet.row_values(row_num)[25])
        else:
            row_num += 1

有人知道哪里出了问题吗?谢谢!

您好像忘记了括号,写了 first_sheet.row_values(row_num[12]) 而不是 first_sheet.row_values(row_num)[12]

因此错误消息是“int is not subscriptable”,意思是“我不明白 row_num[12] 因为 row_num 是一个整数(一个数字),而不是一个列表。”。 =14=]