[Python-Dev] SyntaxError: can't assign to function call

Josiah Carlson jcarlson at uci.edu
Thu Aug 10 20:22:03 CEST 2006


"Phillip J. Eby" <pje at telecommunity.com> wrote:
> 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.
> 
> 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.

Thankfully default dicts in Python 2.5 (they are in, right?) should
solve this particular nit of the language.  And by using default dicts
as an instance __dict__, you get similar behavior for attributes.


> 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.

I'm not sure that your characterization is entirely accurate.  I've
used and seen augmented assignments being used for many years now, and
this is the first time that I've seen anyone propose that it should work.


 - Josiah



More information about the Python-Dev mailing list