Re: SyntaxError: can't assign to a function call
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.python archive

Re: SyntaxError: can't assign to a function call

From: Aahz <aahz@pythoncraft.com>
Date: Wed Mar 01 2006 - 03:00:37 CET

In article <on65021qdcolmvuj0ammt58k35ok14qq46@4ax.com>,
Tim Roberts <timr@probo.com> wrote:
>
>One thing that can be helpful in situations like this is to remember that
>+= in Python isn't quite as "special" as it is in C. So,
>
> f() += [4]
>
>is the same as
>
> f() = f() + [4]
>
>and I think you can see why that is a problem.

Actually, it's not quite the same as the expansion, either:

>>> a=[1]
>>> b=a
>>> a+=[2]
>>> a is b
1
>>> a = a + [3]
>>> a is b
0
>>> a
[1, 2, 3]
>>> b
[1, 2]

-- 
Aahz (aahz@pythoncraft.com)           <*>         http://www.pythoncraft.com/
"19. A language that doesn't affect the way you think about programming,
is not worth knowing."  --Alan Perlis
Received on Sun Apr 30 10:31:58 2006