Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   variable arguments, but on function call (http://www.velocityreviews.com/forums/t371719-variable-arguments-but-on-function-call.html)

devnike 09-20-2006 07:33 AM

variable arguments, but on function call
 
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 ?

devnike 09-20-2006 07:22 PM

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...


All times are GMT. The time now is 08:18 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.