Building a function call? (update)
Duncan Booth
duncan.booth at invalid.invalid
Wed Jul 13 09:47:11 EDT 2005
Francois De Serres wrote:
> Sorry, I was unclear about the fact that the args are formals. I'm
> trying to do something like:
>
> func = "dothat"
> args = ('x','y')
> localcontext = ()
> r = None
> while r is None:
> try:
> r = eval("dothat(x,y)", None, localcontext) #how do I construct
> "dothat(x,y)"? with 'dothat(%s,%s)' % args?
> except NameError:
> ensure_context(args) #find/compute the formals, eg: localcontext
>= (('x', 100), ('y', 200))
I think when your code ends up in as big a mess as this, you need to take a
step back. Forget about asking us how you get at functions or arguments as
strings, instead tell us what problem you are really trying to solve.
I'm pretty sure that whatever your problem is, the solution won't involve
using 'eval', and it almost certainly won't involve looking up variables
or functions from their names.
More information about the Python-list
mailing list