TheSaint wrote:
On 19:06, lunedì 02 giugno 2008 Chris wrote:
actions= ('print', 'sum', 'divide', 'myfunction')
parameters=(5, 'nothing',5.63, object)
8< 8<
getattr(...)
getattr(object, name[, default]) -> value
8< 8<
for nn in actions:
func = getattr(cp, nn)
if callable(func):
func(parameters)
I got the point of Duncan and I should remain on evail() because the
evaluation is made on a construct of string expression, which give me the
final name of the function I want to call.
Why do you still need eval? Can't you just construct the string
describing the function to call and then use getattr() to get the actual
function object to call?
I've tried on Pyshell and clearly said the object str is not callable.
Well no, but I don't think anyone suggested that it would be.
The name of a function to call and the function itself are different
things. getattr() helps you to get from the first to the latter.
Some of those string are functions inside the module, so I was expecting a
sequence of calls according the passed in functions names, but they *must*
be processed as a python statements ;(
This doesn't exactly make sense, as what you want isn't really clear...
Paul
--
http://mail.python.org/mailman/listinfo/python-list