device_properties = ['Device Category', 'Device Count', 'Device Cost']
switcher = {
'Device Category': get_device_category(index),
'Device Count': get_device_count(index),
'Device Cost': get_device_cost(index)
}
for index in range(10):
for j in device_properties:
cat_data[cat] = switcher.get(j, 0)
ここで、呼び出し時に引数として「インデックス」も送信したいと思いますswitcher.get(j, 0)
。つまり、switcher.get((j,index), 0)
switcherdictで定義した関数でindexの値を使用できるようにします。それで、その時に複数の引数を送信する方法switcher.get(j, 0)
や代替手段はありますか?
関数へのポインタを格納し、アクセス時にそれらを呼び出すことができます。
switcher = {
'Device Category': get_device_category,
'Device Count': get_device_count,
'Device Cost': get_device_cost,
}
for index in range(10):
for j in device_properties:
cat_data[cat] = switcher.get(j)(index)
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加