strange behavor....

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Sat Nov 13 17:46:17 EST 2010


On Sat, 13 Nov 2010 21:42:03 +0000, Mark Wooding wrote:

> Dave Angel <davea at ieee.org> writes:
> 
>> No, an (=) assignment is always an assignment.
> 
> No.  In `foo[0] = bar' it's a method call in disguise.

How does that imply that can't also be an assignment?

Of course, you're correct that it's not *necessarily* an assignment, if 
the type of foo is a pathological or broken class that does weird things 
on __setitem__. We tend to gloss over that in discussions, in the same 
way that we gloss over the fact that:

len([1,2,3]) 

does not necessarily return 3, but could in fact do *anything*, depending 
on whether or not len is still the built-in function or not.

I don't think it helps to overload newbies struggling with the basics 
with such pathological cases though.


-- 
Steven



More information about the Python-list mailing list