[Python-Dev] SyntaxError: can't assign to function call
Phillip J. Eby
pje at telecommunity.com
Thu Aug 10 18:31:23 CEST 2006
At 09:24 AM 8/10/2006 -0700, Guido van Rossum wrote:
>On 8/10/06, James Y Knight <foom at fuhm.net> wrote:
> > It makes just as much sense as assigning to an array access, and the
> > semantics would be pretty similar.
>
>No. Array references (x[i]) and attribute references (x.a) represent
>"locations". Function calls represent values. This is no different
>than the distinction between lvalues and rvalues in C.
IIRC, in Lisp a function call can be an lvalue. OTOH, that's probably
because in Lisp there isn't anything besides function calls. :)
I'm having a hard time imagining a use case in Python, though, except to
allow things like "somedict.setdefault(key,0) += 1". And I'm not sure
that's an improvement, although there have certainly been times that I
started to write that, and then grumbled and wrote "somedict[key] =
somedict.setdefault(key,0) + 1" instead.
Honestly, it might make more sense to get rid of augmented assignment in
Py3K rather than to add this. It seems that the need for something like
this springs primarily from the existence of augmented assignment.
More information about the Python-Dev
mailing list