Roy Smith wrote:
In article <4b0a01a...@dnews.tpgi.com.au>, Lie Ryan
wrote:
The semantic of the in-place operator is something like:
x += y
becomes
x = x.__iadd__(y)
Except that the expression x is evaluated just once instead of twice.
thus
foo.bar += baz
becomes
foo.bar = foo.bar.__iadd_
If I've got an object foo, and I execute:
foo.bar += baz
exactly what happens if foo does not have a 'bar' attribute? It's
pretty clear that foo.__getattr__('bar') gets called first, but it's a
little murky after that. Assume for the moment that foo.__getattr__
('bar') returns an object x. I t
On Nov 22, 8:38 pm, Roy Smith wrote:
> In article <4b0a01a...@dnews.tpgi.com.au>, Lie Ryan
> wrote:
>
> > The semantic of the in-place operator is something like:
> > x += y
> > becomes
> > x = x.__iadd__(y)
>
> > thus
> > foo.bar += baz
> > becomes
> > foo.bar = foo.bar.__iadd__(baz)
>
> > So th
> The first statement is creating a whole new list;
Yes but *imo* not quite exactly so.
We can't think of 2 lists as of absolutely independent
things.
... x = [[0]]
... id(x)
19330632
... id(x[0])
19316608
... z = x + [3]
... id(z)
19330312
... id(z[0])
19316608
...
... z[0] is x[0] # ?
True
...
In article <4b0a01a...@dnews.tpgi.com.au>, Lie Ryan
wrote:
> The semantic of the in-place operator is something like:
> x += y
> becomes
> x = x.__iadd__(y)
>
> thus
> foo.bar += baz
> becomes
> foo.bar = foo.bar.__iadd__(baz)
>
> So the call sequence is,
> foo.__getattr__('bar') ==> x
> x.__i
Roy Smith wrote:
In article <4b0a01a...@dnews.tpgi.com.au>, Lie Ryan
wrote:
The semantic of the in-place operator is something like:
x += y
becomes
x = x.__iadd__(y)
thus
foo.bar += baz
becomes
foo.bar = foo.bar.__iadd__(baz)
So the call sequence is,
foo.__getattr__('bar') ==> x
x.__iadd__(
On Nov 22, 9:11 pm, n00m wrote:
> > The first statement is creating a whole new list;
>
> Yes but *imo* not quite exactly so.
> We can't think of 2 lists as of absolutely independent
> things.
> [...]
You are correct that two lists can both have the same mutable object
as items, and if you mutate
On Nov 22, 7:28 pm, Lie Ryan wrote:
> Roy Smith wrote:
> > If I've got an object foo, and I execute:
>
> > foo.bar += baz
>
> > exactly what happens if foo does not have a 'bar' attribute? It's
> > pretty clear that foo.__getattr__('bar') gets called first, but it's a
> > little murky after that.
Roy Smith wrote:
If I've got an object foo, and I execute:
foo.bar += baz
exactly what happens if foo does not have a 'bar' attribute? It's
pretty clear that foo.__getattr__('bar') gets called first, but it's a
little murky after that. Assume for the moment that foo.__getattr__
('bar') return