[Python-Dev] Half-baked proposal: * (and **?) in assignments (original) (raw)
Steve Holden sholden@holdenweb.com
Sat, 23 Nov 2002 12:09:52 -0500
- Previous message: [Python-Dev] Half-baked proposal: * (and **?) in assignments
- Next message: [Python-Dev] Half-baked proposal: * (and **?) in assignments
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
[Gareth]
Since
def f(a,b,*c): ... f(1,2,3,4,5) does (in effect) a=1, b=2, c=(3,4,5), I suggest that a,b,*c = 1,2,3,4,5 [similar suggestions] The motivating principle is that parameter passing is, or should be, just like assignment[1], so what works in one context should work in the other. I've moderately often actually wanted the a,b,*c=... notation, too, usually when using split() on strings containing an unknown number of fields; the most concise alternative goes like a,b,c = (line.split()+[None])[:3] which both looks and feels ugly. The advantage, of course, is the explicit nature.
Of course, you can't take "parameter passing is just like assignment" too seriously here, because
x = 1,2,3 a,b,c = x works, whereas def f(x): ... def g(a,b,c): ... f(1,2,3) g(x) doesn't. Still, the analogy is (to me) quite a compelling one. Am I nuts? Not nuts, but perhaps striving too hard for a false generality. I would support this suggestion if it made the assignment code simpler, but if it complicates it then my feeling is YAGNI.
It's a nice parallel, but n ot one that meets any crying need, IMO.
regards
Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ Previous .sig file retired to www.homeforoldsigs.com
- Previous message: [Python-Dev] Half-baked proposal: * (and **?) in assignments
- Next message: [Python-Dev] Half-baked proposal: * (and **?) in assignments
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]