Passing multiple arguments at the time of using switcher in Python

2251 views python
4

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)

Now I want to send "index" also as argument at the time of calling switcher.get(j, 0). i.e., switcher.get((j,index), 0) so that I can use value of index in my functions that I defined in switcher dict. So, Is there any way to send multiple arguments at the time of switcher.get(j, 0) or any alternatives?

answered question

1 Answer

5

You can store pointers to functions and call them when accessing:

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)

posted this

Have an answer?

JD

Please login first before posting an answer.