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

Stargaming stargaming at gmail.com
Sat Nov 3 09:20:42 CET 2007


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



More information about the Python-list mailing list