"Petr Jakes" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] >I have got names of functions stored in the file. For the simplicity > expect one row only with two function names: printFoo, printFOO > In my code I would like to define functions and then to read function > names from the file, so the functions can be executed in the order the > function names are stored in a file. > > While trying to read the names from the file I am getting always > "strings" and I am not able to execute them. > > I would like to write my code so it will look something like: > > def printFoo(): > print "foo" > > def printFOO(): > print "FOO"
Make a dict mapping names to functions: funs = {'printFoo':printFoo, 'printFOO':printFOO} > # here I would like to read the file with the function names sequences > # and to create tuple which will contain the function names. > # After that I would like to call functions from the tuple: Actually, str.split, the easiest way to separate the multiple names on a line, gives you a list. Same difference to 'for'. funnames=('printFoo', 'printFOO') for fname in funnames: funs[fname]() Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list