variable arguments, but on function call

Joined
Sep 20, 2006
Messages
2
Reaction score
0
Hi,

You all know about "*arg" or "**args" in function definitions : so the function definition doesn't have to know about what are the arguments or how many of them...

Well I need the same concept, but on the caller side !
The function is defined with normal arguments.

I programatically receive the function argument names and values.
I now need to call it...

I'm under Zope, and the function is in fact another python script.
Because of Zope, no "eval" is available.

Calling the function without parameters, or with fixed ones is easy :
zobj=context.restrictedTraverse('path_to_script')
result=zobj()
# or
result=zobj(param1='aa',param2='bb')

Finding its arguments is also easy :
zobj.ZScriptHTML_tryParams()

Now how to make the call when I receive argument values from a list or a dictionery for example (not knowing how many of them) !?

Anybody has a bright idea ?
 
Joined
Sep 20, 2006
Messages
2
Reaction score
0
Solution

[answer to myself]

Althought not super-documented, the solution is simple :

def func(param1,param2):
blahblah


can be called like this:

dict={'param1':'value1','param2','value2'}
result=func(**dict)

so I just have to build a dictionnary...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top