Class Variable Access and Assignment
Steven D'Aprano
steve at REMOVETHIScyber.com.au
Thu Nov 3 10:53:01 EST 2005
On Thu, 03 Nov 2005 13:35:35 +0000, Antoon Pardon wrote:
> Suppose I have code like this:
>
> for i in xrange(1,11):
> b.a = b.a + i
>
> Now the b.a on the right hand side refers to A.a the first time through
> the loop but not the next times. I don't think it is sane that which
> object is refered to depends on how many times you already went through
> the loop.
Well, then you must think this code is *completely* insane too:
py> x = 0
py> for i in range(1, 5):
... x += i
... print id(x)
...
140838200
140840184
140843160
140847128
Look at that: the object which is referred to depends on how many times
you've already been through the loop. How nuts is that?
I guess that brings us back to making ints mutable. I can't wait until I
can write 1 - 0 = 99 and still be correct!
--
Steven.
More information about the Python-list
mailing list