#!/usr/local/bin/python3 from types import MethodType class C(object): def __init__(self): pass #self.__setattr__ = MethodType(s, self) def __setattr__(self, key, value): print('set') if key == 'a': raise Error self.__dict__[key] = value def s(self, key, value): print('set') if key == 'a': raise Error self.__dict__[key] = value c = C() c.a = 1 print(c.a)