Building a function call? (update)

Francois De Serres fdeserres at gmx.net
Wed Jul 13 09:32:46 EDT 2005


Francois De Serres wrote:

>Hiho,
>
>Having a string: "dothat"
>and a tuple: (x, y)
>1. What's the best way to build a function call like: dothat(x,y)?
>
>Assuming dothat is def'd in the same module,
>2. is: eval("dothat(x,y)", None, (('x', 100), ('y', 200)))
>the right way to have it executed?
>
>If dothat is def'd in another module:
>3. what would be the right way to initialize the globals to pass to eval ?
>
>
>TIA,
>Francois
>
>
>  
>
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))

F.







More information about the Python-list mailing list