T
T
Timur Chernyaev2020-02-21 15:04:38
Python
Timur Chernyaev, 2020-02-21 15:04:38

Why does it give an error with the number of arguments?

There is such a function (I attach the script) and a database created in the program (the script is below). Throws the following error: function takes at most 2 arguments(6 given). Why?

def id_base(cursor):
  cursor.execute("""CREATE TABLE IF NOT EXISTS ids
                      (
                       id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
                       surname TEXT,
                       name TEXT,
                       patronymic TEXT,
                       class INTEGER
                       books TEXT
                       )
                   """)
  '''return cursor?'''
def registration(cursor):
    SURNAME = input('Введи фамилию (Например, Иванов): ')
    NAME = input('Как тебя зовут?(Например, Иван): ')
    PATRONYMIC = input('Введи отчество (Например, Иванович: ')
    CLASS = input('В каком классе ты учишься? (Например, 6А) : ')
    cursor.execute('INSERT INTO ids (name, surname, patronymic, class) VALUES (?, ?, ?, ?)', NAME, SURNAME, PATRONYMIC, CLASS)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2020-02-21
@ProgramistNoob

Because Sqlite accepts a tuple:

cursor.execute('INSERT INTO ids (name, surname, patronymic, class) VALUES (?, ?, ?, ?);', (NAME, SURNAME, PATRONYMIC, CLASS))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question