variable arguments, but on function call

Discussion in 'Python' started by devnike, Sep 20, 2006.

  1. devnike

    devnike

    Joined:
    Sep 20, 2006
    Messages:
    2
    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, Sep 20, 2006
    #1
    1. Advertising

  2. devnike

    devnike

    Joined:
    Sep 20, 2006
    Messages:
    2
    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...
    devnike, Sep 20, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. grbgooglefan
    Replies:
    2
    Views:
    403
    Pascal Bourguignon
    Jan 30, 2008
  2. grbgooglefan
    Replies:
    4
    Views:
    425
    Kenny McCormack
    Jan 30, 2008
  3. grbgooglefan
    Replies:
    0
    Views:
    374
    grbgooglefan
    Jan 30, 2008
  4. moreau.steve@gmail.com
    Replies:
    3
    Views:
    798
    moreau.steve@gmail.com
    Dec 31, 2008
  5. Navaneeth
    Replies:
    4
    Views:
    536
    Kenny McCormack
    Nov 20, 2010
Loading...

Share This Page