python - Python3 taking function name as parameter and call it with parameter -
i need take name of function want call parameter list. achieved code (the result b. if liste[0] result a, works.):
def a(): print("aaaa") return none def b(): print("bbbb") return none liste = ['a','b'] inputmethodname = liste[1] locals()[inputmethodname]()
but in example same thing(at least see in way thats why ask question), giving error. code is:
filterpassflag = 1 controllistforfilter = ['firstcharcontroller'] def firstcharcontroller(singleline): if singleline[0] == "1": filterpassflag = 0 return none def startcontrol(singleline): controllistforfilteriterator = 0 while (controllistforfilteriterator < len(controllistforfilter)) & (filterpassflag == 1): inputmethodname = controllistforfilter[controllistforfilteriterator] locals()[inputmethodname](singleline) #******error in line. controllistforfilteriterator = controllistforfilteriterator + 1 return none singleline = "bla bla bla bla" startcontrol(singleline)
output is:
> traceback (most recent call last): file > "c:/users/berkays/desktop/phyondeneme/phytontest.py", line 37, in > <module> > startcontrol(singleline) file "c:/users/berkays/desktop/phyondeneme/phytontest.py", line 24, in > startcontrol > locals()[inputmethodname](singleline) keyerror: 'firstcharcontroller' process finished exit code 1
when delete line contains error (local() line) program working. difference between 2 example?