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

J

jmborr

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
 
S

Stargaming

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
 

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

No members online now.

Forum statistics

Threads
474,434
Messages
2,571,691
Members
48,796
Latest member
Greg L.

Latest Threads

Top