问题描述
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)
时也将“ index”作为参数发送。
即switcher.get((j,index), 0)
以便我可以在switcher dict中定义的函数中使用index的值。
那么,有没有办法在switcher.get(j, 0)
或任何替代方法时发送多个参数?
1楼
您可以存储指向函数的指针,并在访问时调用它们:
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)