I'm quite new in Python, but googling around did not match any answer for it .
I created a module, containing 10 GUI buttons classes. To use a button I write in code ButtonLib.TypeA(**kwargs)
, ButtonLib.TypeB(**kwargs)
and so on.
kwargs
is same for all buttons.
Buttons ( amount and type ) are selected by user (stored in button_type_vector
) and not known in advance.
I wish to know if there is a way writing code more efficiently rather than:
for x in button_type_vector:
if x == 'TypeA':
ButtonLib.TypeA(**kwargs)
elif x== 'TypeB' :
ButtonLib.TypeB(**kwargs)
and so on.
by efficiently I mean something like:
for x in button_type_vector:
ButtonLib.x(**kwargs)
thnks