You can convert the current code to this one :
...
def add_data(cursor):
id = input("Insert 'id':")
abbrev = input("Insert abbrev:")
latin = input("Insert latin:")
common = input("Insert common:")
expression=f'INSERT INTO species VALUES (?,?,?,?)'
cursor.execute(expression,(id,abbrev,latin,common,))
def main(db_file):
con, cur = get_connection(db_file)
adddata = add_data(cur)
con.commit()
main('data.db')
where
- the redundant
for
cursor is removed
- the
DML
statement is committed
- the placeholders for variables should be converted to the question marks,
rather than explicit variable names, as being securer, while creating a
parameter list as a tuple with four elements within the
execute
function
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…