Force exception on attribute write access only one object

Peter Otten __peter__ at
Thu Jan 8 12:29:19 CET 2009

Thomas Guettler wrote:

> for debugging I want to raise an exception if an attribute is
> changed on an object. Since it is only for debugging I don't want
> to change the integer attribute to a property.

> This should raise an exception:
> Background:
> Somewhere this value gets changed. But I don't now where.

If you change your mind:

class A(object):
    def __init__(self): = 42

a = A()
b = A()

class B(A):
    def foo(self):
        return self.__dict__["foo"]

b.__class__ = B = "whatever"
print = "whatever"


More information about the Python-list mailing list