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