471,310 Members | 1,362 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,310 software developers and data experts.

how to pass a function name and its arguments inside the arguments of other function?

I need something like this:

1: superfoo( non-keyword-args, keyword-args, methodname, *kargs,
*kwargs):
2: """non-keyword-args and keyword-args are arguments that
3: apply to superfoo, while *kargs and **kwargs are
arguments
4: that apply to methodname. See below"""
5: object=someClass()
6: result=getattr(object,methodname)(*kargs,**kwargs)
7: return result

The problem is: how can I pass both arguments for superfoo and
methodname in line 1: ? Is it possible?
-Jose

Nov 3 '07 #1
1 1040
On Sat, 03 Nov 2007 02:21:30 +0000, jmborr wrote:
I need something like this:

1: superfoo( non-keyword-args, keyword-args, methodname, *kargs,
*kwargs):
2: """non-keyword-args and keyword-args are arguments that 3:
apply to superfoo, while *kargs and **kwargs are arguments
4: that apply to methodname. See below""" 5:
object=someClass()
6: result=getattr(object,methodname)(*kargs,**kwargs) 7:
return result

The problem is: how can I pass both arguments for superfoo and
methodname in line 1: ? Is it possible? -Jose
I don't really understand the problem (could you give some (fictional)
working sample how you plan to use this and leave out the line numbers
for better readability?) but perhaps using traditional tuples and dicts
instead of */** unpacking would be enough? Like::

superfoo(fooargs=(1,2,3), fookwargs={'foo': 'bar},
objargs=('a', 'b'), objkwargs={'x': 5})

Cheers,
Stargaming
Nov 3 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

41 posts views Thread by Berk Birand | last post: by
4 posts views Thread by jrefactors | last post: by
14 posts views Thread by James Thiele | last post: by
14 posts views Thread by Abhi | last post: by
6 posts views Thread by lisp9000 | last post: by
12 posts views Thread by Bryan Parkoff | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.