Op 2005-11-03, Steven D'Aprano schreef <[EMAIL PROTECTED]>: > On Thu, 03 Nov 2005 04:30:09 -0800, Paul Rubin wrote: > >> Steve Holden <[EMAIL PROTECTED]> 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.
No it isn't. One other way, to implement the += and likewise operators would be something like the following. Assume a getnsattr, which would work like getattr, but would also return the namespace where the name was found. The implementation of b.a += 2 could then be something like: ns, t = getnsattr(b, 'a') t = t + 2 setattr(ns, 'a') I'm not arguing that this is how it should be implemented. Just showing the implication doesn't follow. -- Antoon Pardon -- http://mail.python.org/mailman/listinfo/python-list