rrr at ronadam.com
Thu Mar 8 06:54:10 CET 2007
Greg Ewing wrote:
> Ron Adam wrote:
>> Greg Ewing wrote:
>>> Ron Adam wrote:
>>>> Also the '*' syntax can't be used to unpack nested items.
>>> Makes perfectly good sense to me.
>> Didn't say it didn't.
> Then I still don't know what you meant by your original
> comment. What kind of nested item unpacking would you
> like to do that the * syntax wouldn't handle?
This was what I was that originally referring to.
data = [1, 2, [3, 4], 5]
a, b, c, d, e = data # can't unpack [3,4] here with *
a, b, [c, d], e = data # must use  on the left side instead
>> Symmetry is not always the best solution. Sometimes asymmetry is good
>> because it can communicate a different context more clearly.
> Perhaps, but why do you think that the symmetry we already
> have between packing and unpacking is okay, but a new
> symmetry involving * wouldn't be okay?
The * is used mostly with names and they tend to look more alike than the
equivalent packing or unpacking using () or  in more situations. The ()
and  are much more explicit in both packing and unpacking operations.
I like the packing and unpacking features of python very much, it's just I
would like it a bit more if the '*' symbol for packing and unpacking were
different in this particular case. And especially so if '*' packing and
unpacking features are used in a more general way.
def foo(*args, **kwds): # packs here
bar(&args, &&kwds): # unpacks here
a, b, *c = a, b, c, d # packs here
a, b, c = &items # unpacks here
It would just be easier for me to see and keep in my head while I'm working
with it. I'm not sure I can explain it better than that, or say exactly
why as it probably has more to do with how my brain works than weather it
is okay or not okay in any programing sense.
Is that clearer? (I don't expect this to be changed)
More information about the Python-ideas