forwarding *arg parameter

Stargaming stargaming at gmail.com
Sun Nov 5 13:55:48 EST 2006


Tuomas schrieb:
> Tuomas wrote:
> 
>> def g(*arg):
>>     return arg
>>
>> def f(*arg):
>>     return g(arg)
>>
>> How can g know if it is called directly with (('foo', 'bar'),) or via 
>> f with ('foo', 'bar'). I coud write in f: return g(arg[0], arg[1]) if 
>> I know the number of arguments, but what if I don't know that in 
>> design time?
> 
> 
> So it seems that I would like to have an unpack operator:
> 
> def f(*arg):
>     return(!*arg)
> 
> TV

Either you take one of the snippets here:
http://aspn.activestate.com/ASPN/search?query=flatten&section=PYTHONCKBK&type=Subsection
or just use arg[0] clever (as mentioned a few times in this thread).



More information about the Python-list mailing list