Unpacking sequences and keywords in one function call

OKB (not okblacke) brenNOSPAMbarn at NObrenSPAMbarn.net
Tue Nov 14 19:20:01 CET 2006


Dennis Lee Bieber wrote:

> On Tue, 14 Nov 2006 05:45:57 GMT, "OKB (not okblacke)"
> <brenNOSPAMbarn at NObrenSPAMbarn.net> declaimed the following in
> comp.lang.python:
> 
>> 
>>          I was just wondering about this yesterday.  Is there a
>>          reason you 
>>     can only unpack a sequence at the END of the positional
>>     argument list? 
> 
>      Not a reasoned explanation, but... Python has to be able to
>      assign 
> "defined" parameters before gathering the */** parameters.

    	Sorry, I don't really understand what you mean by that.  I'm 
talking about the UNpacking of a sequence into separate function 
arguments, which I was assuming happened on the "outside" at the time 
the function was called.  That is, why aren't these two calls exactly 
the same:

a = [2,3]
f(1, *a, 4)
f(1, 2, 3, 4)

    	I don't understand why Python would need to assign "defined 
parameters" first -- the sequence unpacking here can happen before 
anything is mapped to the function parameters at all.  (Can't it?)

    	I can see why moving the kwargs up earlier in the list isn't valid, 
because it isn't valid for normal argument-passing either; switching the 
order of individually named kwargs and a **dict isn't meaningful because 
the kwargs aren't ordered anyway.  But is there a reason you can't 
unpack a sequence into the middle of the positional argument list?

-- 
--OKB (not okblacke)
Brendan Barnwell
"Do not follow where the path may lead.  Go, instead, where there is
no path, and leave a trail."
	--author unknown



More information about the Python-list mailing list