Home > Software design >  TypeError: function takes at most 2 arguments (4 given)
TypeError: function takes at most 2 arguments (4 given)

Time:10-01

I work with the sqlite3 database. An error occurs in the last line - cursor.execute("INSERT INTO player VALUES(?,?,?);", playe, leve, balance) TypeError: function takes at most 2 arguments (4 given)

import sqlite3

connect = sqlite3.connect("Stats.db")
cursor = connect.cursor()

cursor.execute("""CREATE TABLE IF NOT EXISTS player(
    name TEXT,
    cash INT,
    level INT
)""")
connect.commit()

playe = input("Name: ")
balance = 10
leve = 0
cursor.execute("INSERT INTO player VALUES(?,?,?);", playe, leve, balance)

CodePudding user response:

Use tuple

cursor.execute("INSERT INTO player VALUES(?,?,?);", (playe, leve, balance))

I saw you wrote that the data is not inserted, you can do as follows to solve this:

connect.commit()
connect.close()

CodePudding user response:

When using cursor.execute you need to pass the values as a tuple or list (or any iterator).

You can do so by simply replacing playe, leve, balance with (playe, leve, balance).

Full line:

cursor.execute("INSERT INTO player VALUES(?,?,?);", (playe, leve, balance))
  • Related