Building a function call? (update)

Francois De Serres fdeserres at gmx.net
Wed Jul 13 09:59:40 EDT 2005


Duncan Booth wrote:

>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.
>  
>
Sure? okay, let me take the time to formulate a thorough blueprint of my 
context, and I'll come back to you...
F.




More information about the Python-list mailing list