To generate a dictionary format:
: supplier=[{
'name' : 'creative digital technology co., LTD.,
'province' : 'in guangdong,
'city' : 'shenzhen',
'contact' : 'Zhang Sanfeng',
'phone', '13800000000',
'the product: [
{' product_name ':' office stationery ', 'sub' : [{' name ':' pen ', 'price', '3', 'unit' : 'a'}, {' name ':' paper ', 'price' : '30', 'unit' : 'package'}, {' name ':' notepad ', 'price' : '4.5', 'unit' : 'this'}],
{' product_name ':' computer ', 'sub' : [{' name ':' laptop ', 'price', '5800', 'unit' : 'units'}]}
]
},
{
'name' : 'ABC',
'province' : 'Shanghai',
'city' : ' ',
'contact' : 'Reese Cathy',
'phone', '87900000',
'the product: [
{' product_name ':' instructions sheet ', 'sub' : [{' name ':' the prophase planning, 'price', '1000', 'unit' : 'set'}, {' product_name ':' real estate marketing piece, 'sub' : [{' name ':' the prophase planning, 'price' : '3000', 'unit' : 'set'}]}
]
},
]
CodePudding user response:
Read excel to listTraverse the list
Set up three layers of nested dictionaries,
List the inner value of the dictionary is traversed to determine whether a list, if there is append
Looks like this,