Why is "unpacking" of tuples only allowed when there's 1 tupple ?

Stef Mientki stef.mientki at gmail.com
Sat Aug 15 17:19:53 EDT 2009


thanks Jan,
for the clear explanation.
cheers,
Stef

Jan Kaliszewski wrote:
> Dnia 15-08-2009 o 22:50:39 Stef Mientki <stef.mientki at gmail.com> 
> napisał(a):
>
>> hello,
>>
>> I'm not sure if  "unpacking" is the right term
>> but if I have a tuple of 2 arrays,
>> I can either call a function with:
>>
>>           Space_State = tf2ss ( filt[0], filt[1] )
>>
>> or with
>>           Space_State = tf2ss ( *filt )
>>
>> Now if I've to call a function with more parameters,
>> why can't I use (Polynome is again a tuple of 2 arrays) :
>> (which already gives an error in the IDE)
>>
>>           Respons = signal.lfilter ( *Polynome, Signal )
>>
>> and thus I've to use:
>>
>>           Respons = signal.lfilter ( Polynome[0], Polynome[1], Signal )
>
> The content of that tuple or list (filt/Polynome here) doesn't matter.
> Simply, when calling function, you can't put positional (non-keyword)
> argument after *something.
>
>  >>> def nic(*args, **kwargs): pass
>  ...
>  >>> nic(*[1,2,3], 4)
>    File "<stdin>", line 1
>  SyntaxError: only named arguments may follow *expression
>
>
> That'd be ok:
>
>  Respons = signal.lfilter(*Polynome, sig=Signal)  # if this method can
>                                                   # receive argument
>                                                   # 'sig' after more
>                                                   # than len(Polynome)
>                                                   # of arguments
>




More information about the Python-list mailing list