TheSaint <[EMAIL PROTECTED]> wrote: > actions= ('print', 'sum', 'divide', 'myfunction') > parameters=(5, 'nothing',5.63, object) > > for routines in actions: > routines(parameters) > > I'd like to note that actions are string or string expressions of the > program functions or python itself, so I've in my program something > like: > > for nn in actions: > eval('cp.%s' %nn) > > Where cp is an instance. > > So I'm asking here whether exist a way that these string become > functions inside my program, without using eval()
eval('cp.%s' %nn) is more cleanly done as: getattr(cp, nn) In the more general case, you could just use the functions/methods directly instead of using their names: actions = (cp.Print, cp.sum, cp.divide, cp.myfunction) for nn in actions: nn(parameters) -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list