python面向对象__call__

call

任何对象后面加(),触发执行。


class People:
    def __init__(self,name):
        self.name = name

    def __call__(self, *args, **kwargs):
        print("call")


class Student(People):
    def walk(self):
        print("walking....")
p=People("egon")

print(callable(People))
print(callable(p))
s =Student("allen")
s()

执行结果

True
True
call
posted @ 2017-05-02 17:02  Great_kyle  阅读(212)  评论(0编辑  收藏  举报