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
Post a Comment