Class Variable Access and Assignment
Steven D'Aprano
steve at REMOVETHIScyber.com.au
Thu Nov 3 09:45:35 EST 2005
On Thu, 03 Nov 2005 04:30:09 -0800, Paul Rubin wrote:
> Steve Holden <steve at holdenweb.com> writes:
>> > class A:
>> > a = 1
>> > b = A()
>> > b.a += 2
>> > print b.a
>> > print A.a
>> > Which results in
>> > 3
>> > 1
>> >
>> I don't suppose you'd care to enlighten us on what you'd regard as the
>> superior outcome?
>
> class A:
> a = []
> b = A()
> b.append(3)
> print b.a
> print a.a
>
> Compare and contrast.
I take it then that you believe that ints like 1 should be mutable like
lists? Because that is what the suggested behaviour implies.
Ah, what a grand thing that would be! We could say:
0 += 1
1 += 2
7 -= 1
and then have 0 + 1 == 7. Think of the obfuscated code we could write!
--
Steven.
More information about the Python-list
mailing list