■ Data after extraction: Variable name: name
['nameA', 'nameB', 'nameC', 'nameD']
■ sqlite3:table name:user
header:name
■ After storing sqlite3
name
nameA
nameB
nameC
nameD
I want to store it as above.
I tried as below, but the variable name goes straight into one line.
I want to store the namesA-D in the database one line at a time.
# variable
name = '\n'.join(name)
# DB processing
dbpath="user.db"
con=sqlite3.connect(dbpath)
cursor=con.cursor()
sql = 'INSERT INTO user(name) VALUES(?)'
cursor.execute(sql,(name,))
con.commit()
con.close
Do not process name='\n'.join(name)
, but try the cursor.execute(sql,(name,))
part as follows:
for entry in name:
cursor.execute(sql, (entry,))
© 2024 OneMinuteCode. All rights reserved.