Home > Back-end >  Append multiple lists with another set of lists python and format to insert into datatable
Append multiple lists with another set of lists python and format to insert into datatable

Time:04-13

I have items collected from variable number of 'paired' entry widgets and other predefined data. the 'paired' entry widgets are 'quantity' and 'sell price'.

So far, I can create 2 seperate 'sets of lists' (not formatted how i think they should be).

1
2
3
4

('SO6666', 'PW071', 'Orange', ('M',), '10')
('SO6666', 'PW071', 'Orange', ('L',), '20')
('SO6666', 'PW071', 'Orange', ('XL',), '30')
('SO6666', 'PW071', 'Orange', ('XXL',), '40')

In the example the 1 2 3 4 is the Quantity and the 10 20 30 40 is the sell price. I need to format the lists correctly for inserting into a datatable and appended the 2 sets of lists.

def addtoorder():
global all_entries , quantity, e, orderref, SO, c, d, sellprice, size, all_prices
orderref = SO.get()

for size, quantity in all_entries[e.get()].items():
    x = quantity.get()  
    print(x)

for size, sellprice in all_prices[e.get()].items():
    y = sellprice.get()
    sell=orderref, c.get(), d.get(), size , y
    print(sell)

I believe the required format for inserting into datatable would be

('SO6666', 'PW071', 'Orange', 'M', '10', '1')
('SO6666', 'PW071', 'Orange', 'L', '20', '2')
('SO6666', 'PW071', 'Orange', 'XL', '30', '3')
('SO6666', 'PW071', 'Orange', 'XXL', '40', '4')

Thanks for your help.

CodePudding user response:

 def addtoorder():
    global all_entries , quantity, e, orderref, SO, c, d, sellprice, size, all_prices
    orderref = SO.get() 

all_prices=all_prices[e.get()].items()
all_entries= all_entries[e.get()].items()

for prices,entries in zip(all_prices,all_entries):
    y = prices[1].get()        
    x = entries[1].get()  
    sell=orderref, c.get(), d.get(), prices[0] , y, x
    print(sell)
  • Related