Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   how to pass a function name and its arguments inside the arguments of other function? (http://www.velocityreviews.com/forums/t549021-how-to-pass-a-function-name-and-its-arguments-inside-the-arguments-of-other-function.html)

jmborr 11-03-2007 02:21 AM

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


Stargaming 11-03-2007 08:20 AM

Re: how to pass a function name and its arguments inside thearguments of other function?
 
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


All times are GMT. The time now is 04:26 AM.

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