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

时间:2016-12-07 00:18:48

标签: tuples create-table

我正在为我的GCSE做一个简单的例行工作并且有点卡住了。不幸的是,我的老师不是编码员,当我们遇到困难时总是将课程引用给Google!

我一直收到这个错误。

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("SELECT GTIN8 From Products WHERE GTIN8=?", (validcode,))

        found = c.fetchone()

        barcode = found[0]
        productinfo = found[1]
        price = found[2]

        c.execute("INSERT INTO ProductData (barcode,productinfo,price) VALUES(?,?,?)")
        db_new.commit()
        print(barcode, productinfo, price)

查询此表

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)

我已经摸不着头疼,想知道为什么第二栏没有被退回!

请有人给我一个转向。

由于

0 个答案:

没有答案