__call__直接对实例进行调用

class Student(object):
    def __init__(self, name):
        self.name = name

    def __call__(self):
        print('My name is %s.' % self.name)


>>> s = Student('Michael')
>>> s() # self参数不要传入
My name is Michael.

你可能感兴趣的:(__call__直接对实例进行调用)