forwarding *arg parameter

Tuomas tuomas.vesterinen at pp.inet.fi
Mon Nov 6 13:37:17 CET 2006


Dennis Lee Bieber wrote:
> On Sun, 05 Nov 2006 22:51:00 GMT, Tuomas <tuomas.vesterinen at pp.inet.fi>
> declaimed the following in comp.lang.python:
> 
> 
>>> 
>>
>>I fylly agree with tis: "Typically, the responsibility should be on the 
>>CALLER, not the CALLED..". I just don't know how to unpack *arg for 
>>calling g. I can get the len(arg), but how to formulate an unpacked call 
>>g(arg[0], arg[1], ..). Building a string for eval("g(arg[0], arg[1], 
>>..)") seems glumsy to me.
>>
> 
> 	Did you miss the example I gave? Using "*args" on the "def"
> essentially says "pack remaining arguments into one tuple". Using
> "*args" on a CALL says "UNPACK tuple into positional arguments"
> 
> def f(*args):	<<<< pack arguments into tuple

Thats it:

> 	x = g(*args)	>>>> unpack args tuple when calling

Yesterday I tested something like this and got a syntax error. So I got 
misunderstanding that "g(*args)" is'nt a proper syntax. Obviously my 
test sentence had some other syntax error. Sorry.

TV



More information about the Python-list mailing list