mysql - Using Sqlite3 to insert data into database using a loop -


i'm getting started databases , use inserting information database using loop.

i made simple database table 3 headings: isbn, author, price.

i use lists containing isbns, authors, , prices , insert each isbn, author, , price database table using 1 loop.

here code:

isbn1=isbns[0] author1=authors[0] price1=prices[0]   db=sqlite3.connect('my_book_inventory.sqlite') cursor=db.cursor() cursor.execute('''insert isbns(isbn,author,price) values(?,?,?)''',(isbn1,author1,price1)) db.commit()   

could me inserting each isbn manually calling values in lists isbn1, isbn2, isbn3 etc. doing loop?

lets have n records want insert them. assuming isbns, authors , prices arrays of size n, can this:

for in range(0, n):     isbn = isbns[i]     author = authors[i]     price = prices[i]      db=sqlite3.connect('my_book_inventory.sqlite')     cursor=db.cursor()     cursor.execute('''insert isbns(isbn,author,price) values(?,?,?)''',(isbn,author,price))     db.commit() 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -