简体   繁体   中英

TypeError: unsupported operand type(s) for -: 'int' and 'builtin_function_or_method'

I am attempting to minus a user inputted integer from product_qty within my sqlite3 database and I am getting this error:

TypeError: unsupported operand type(s) for -: 'int' and 'builtin_function_or_method'

These are the two functions that are involved when giving this error.

def Move():
        curItem = tree.focus()
        print (tree.item(curItem))
        contents = (tree.item(curItem))
        getvalue = contents.get('values')
        print(getvalue)
        selecteditem = contents['values']
        updateStock(id, getvalue[0])
        Database()
        cursor.execute("INSERT INTO `basket` VALUES(?, ?, ?, ?)", getvalue)
        conn.commit()
        PRODUCT_ID.set("")
        PRODUCT_NAME.set("")
        PRODUCT_PRICE.set("")
        PRODUCT_QTY.set("")
        conn.close()

def updateStock(qty, id):
        t = (id,)
        Database()
        cursor.execute("SELECT product_qty FROM product WHERE product_id = ?", t)
        old_qty = cursor.fetchone()
        new_qty = 0
        new_qty = int(old_qty[0]) - qty
        cursor.execute("UPDATE product SET product_qty = ? WHERE product_id = ?", (new_qty, id))
        conn.commit()
        conn.close()

You're passing the builtin id function to updateStock . That does not end well. I'd avoid that name for variables. You need to find a way to determine the ID you're interested in, in your Move function.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM