classTest(): def__str__(self): return'this is a test class' def__getattr__(self,key): # key 就是不存在的那个函数名。 print('这个key:{}并不存在。'.format(key)) def__setattr__(self,key,value): print(key,value) self.__dict__[key] = value print(self.__dict__) def__call__(self,a): print('__call__ has being start') print(a)
t = Test() print(t) t.a t.name = '小木'# name 和小木属于类中不存在的属性和值。 t('dewei') print('____________________\n')