python - Define a function head inside a conf file -
i using dictionary/get construct switch case in python. looks similar one:
def switch_function(pluginid, param): switcher = { 'someid': somefunction(param), } return switch_function.get(pluginid, none)
however, want to extend dictionary key value pair, defined in conf file. want function head value. function head should head of function, should executed in switch case, specific pluginid. config file this:
[asection] pluginid='anotherid' functionhead: anotherfunction2
extending dictionary should easy, possible map function head value inside conf file?
the following example give exec
clause. dict
should extend this:
switcher[config["asection"]["anotherid"])] = func
then need define func this:
#conf #[asection] #pluginid='anotherid' #functionhead: anotherfunction2 #python #config instance of config parser def func (param): exec ("%s(param)" % config["asection"]["functionhead"])
this call function called anotherfunction2
have defined. call func this:
switcher[config["asection"]["anotherid"])](param)
hope helps!