スプレッドシートがあり、xlrd を使用して Python に解析しています。
私はそれを(他のシートを含めて)次のような辞書のリストにまとめる必要があります:
[{"price4-0": 18.22, "price4-1": 21.23, "price4-4": 25.65, "quantity": 100.0, "turnaround": "1days", "size": "2 x 2"},
{"price4-0": 16.44, "price4-1": 19.43, "price4-4": 23.54, "quantity": 200.0, "turnaround": "1days", "size": "2 x 2"}...]
したがって、「ターンアラウンド」辞書の値はシート名から取得され、他の辞書キーは最初の行の値です。私はそれを書き込もうとしているので、別のシートまたは別の行が追加されても機能します。基本的にループして、適切な場所に適切な値を追加します。正しい結果が得られるハードコードされたバージョンがありますが、動的である必要があります。
from pprint import pprint
import xlrd
wb = xlrd.open_workbook('cardprice.xls')
pricelist = []
for i, x in enumerate(wb.sheets()):
for r in range(x.nrows)[1:]:
row_values = x.row_values(r)
pricelist.append({'turnaround':x.name,
'size':row_values[0],
'quantity':row_values[1],
'price4-0':row_values[2],
'price4-1':row_values[3],
'price4-4':row_values[4]
})
pprint(pricelist)