python学习之内建属性2

1内建属性的坑:

    

class Person():
    def __getattribute__(self, item):
        print('执行属性拦截')
        if(item.startswith('a')):
            return 'hahaha'
        else:
            return self.test



    def test(self):
        print('heihei...')


p = Person()
p.a

p.b#产生了递归调用...导致程序出错.

    

猜你喜欢

转载自blog.csdn.net/Bruce_Zhang0828/article/details/80994662