Tuples 元组索引超出范围c.fetchone()

Tuples 元组索引超出范围c.fetchone(),tuples,create-table,Tuples,Create Table,我正在为我的普通中等教育证书做一个简单的程序,有点卡住了。不幸的是,我的老师不是一个程序员,当我们陷入困境时,他总是让全班同学去谷歌 我一直在犯这个错误 Traceback (most recent call last): File "F:\Controlled assesment Task 2 - Copy.py", line 33, in <module> productinfo = found[1] IndexError: tuple index out of range 查

我正在为我的普通中等教育证书做一个简单的程序,有点卡住了。不幸的是,我的老师不是一个程序员,当我们陷入困境时,他总是让全班同学去谷歌

我一直在犯这个错误

Traceback (most recent call last):
File "F:\Controlled assesment Task 2 - Copy.py", line 33, in <module>
productinfo = found[1]
IndexError: tuple index out of range
查询此表

c.execute("CREATE TABLE Products(GTIN8 string, Product_Description text, Cost float)") #Creates a table with fields and data types
Products=[['12345670','TShirt', 10.00],
     ('52647819','Shirt', 20.00),       #This is the product table
     ('15678348','Polo', 15.00),
     ('15975324','Hoodie', 30.00),
     ('42675136','Dress', 20.00),
     ('42697312','Skirt', 12.00),
     ('86316422','Shorts', 18.00),
     ('17653749','Jeans', 35.00),
     ('93462815','Socks', 5.00),
     ('00000000','test', 1.50),
     ('36478545','Shoes', 40.00)]
c.executemany("INSERT INTO Products VALUES (?,?,?)",Products)
我头痛不已,想知道为什么第二列没有返回

有人能给我一头牛吗


谢谢

我不知道这是用什么语言写的,但一般来说,
索引超出范围
意味着你使用的是
[n]
位置没有任何内容。它提到了
productinfo=found[1]
,所以我猜
found
没有
[1]
。如果删除该行,它是否会为
price=found[2]
给出相同的错误?它是用Python 3.5编写的。Found[0]表示表的第一列,已成功返回[1],[2]表示未返回的第二列和第三列。删除[1]会导致[2]出现相同的错误。我正在尝试让用户输入一个经过验证的条形码,并设置购买x个与该条形码相关的单元。查询应返回正确输入的条形码返回的行的内容。我想创建一个新的db表,其中包含与条形码相关的退货产品和成本信息。单位数量乘以总成本和总产量。我想我把它修好了!我将变量GTIN8替换为c.execute处的星号(“从产品中选择GTIN8,其中GTIN8=?”,(validcode,))
c.execute("CREATE TABLE Products(GTIN8 string, Product_Description text, Cost float)") #Creates a table with fields and data types
Products=[['12345670','TShirt', 10.00],
     ('52647819','Shirt', 20.00),       #This is the product table
     ('15678348','Polo', 15.00),
     ('15975324','Hoodie', 30.00),
     ('42675136','Dress', 20.00),
     ('42697312','Skirt', 12.00),
     ('86316422','Shorts', 18.00),
     ('17653749','Jeans', 35.00),
     ('93462815','Socks', 5.00),
     ('00000000','test', 1.50),
     ('36478545','Shoes', 40.00)]
c.executemany("INSERT INTO Products VALUES (?,?,?)",Products)