SyntaxError: can't assign to a function call

Fuzzyman fuzzyman at gmail.com
Sun Feb 26 18:58:58 EST 2006


Alex Martelli wrote:
> Fuzzyman <fuzzyman at gmail.com> wrote:
>
> > What gives ?
>    ...
> > >>> a = []
> > >>> def f():
> >       return a
>    ...
> > >>> f() += [4]
> > SyntaxError: can't assign to function call
>
> Exactly what the error message says: it's syntactically forbidden to
> perform any assignment on a function-call.
>
> If you're keen on these semantics, use for example
>
> f().extend([4])
>

Cool, thanks. That's what I did, it's just not an error I'd seen
before. Everywhere else Python evaluates the function call and then
does it's stuff with the result.

All the best,

Fuzzyman

> which IS quite legal (or, if you know the RHS list has only one item,
> f().append(4) is clearer and more effective).
> 
> 
> Alex




More information about the Python-list mailing list