Python Forum
Inserting values from multiple lists sqlite
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Inserting values from multiple lists sqlite
#1
  for item1, item2 in cartproducts, cartprices:
        c.executemany("INSERT INTO orders(Product_Name, Product_Price) VALUES(?, ?);", (item1, item2, ))
   connection.commit()
I'm currently having issues inserting values from two different lists to my database. I've got the code working for just adding values from one list, but I'm stumped on how to use a second. I need to add the Product Name and Prices together or they just end up separated. Right now I'm getting the error ValueError: too many values to unpack (expected 2) and I'm not sure what the fix is.
Reply
#2
I do not know how sqlite works. And you don't give information on your datastructures. But I guess cartproducts and cartprices are lists. So I think you will have to zip those together.
for item1, item2 in zip(cartproducts, cartprices):
      c.executemany("INSERT INTO orders(Product_Name, Product_Price) VALUES(?, ?);", (item1, item2, ))
 connection.commit()
(untested)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  __init__() got multiple values for argument 'schema' dawid294 4 1,899 Jan-03-2024, 09:42 AM
Last Post: buran
  python convert multiple files to multiple lists MCL169 6 1,436 Nov-25-2023, 05:31 AM
Last Post: Iqratech
  user input values into list of lists tauros73 3 1,025 Dec-29-2022, 05:54 PM
Last Post: deanhystad
  How to combine multiple column values into 1? cubangt 15 2,634 Aug-11-2022, 08:25 PM
Last Post: cubangt
  Help with subtracting values using SQLite & Python Extra 10 3,288 May-10-2022, 08:36 AM
Last Post: ibreeden
  Generate a string of words for multiple lists of words in txt files in order. AnicraftPlayz 2 2,759 Aug-11-2021, 03:45 PM
Last Post: jamesaarr
  Create Dict from multiple Lists with duplicate Keys rhat398 10 3,987 Jun-26-2021, 11:12 AM
Last Post: Larz60+
  Function - Return multiple values tester_V 10 4,321 Jun-02-2021, 05:34 AM
Last Post: tester_V
  Better way to append frames from a video to multiple lists? Balaganesh 0 1,822 May-13-2021, 07:37 AM
Last Post: Balaganesh
  Xlsxwriter: Create Multiple Sheets Based on Dataframe's Sorted Values KMV 2 3,442 Mar-09-2021, 12:24 PM
Last Post: KMV

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020