Discuss / Python / 关于 callable

关于 callable

Topic source

VincyChan4231

#1 Created at ... [Delete] [Delete and Lock User]

我这里使用 Win7 Python3.8.6,

如果

class Student(object):

    def __init__(self, name):

        self.name = name

    def __call__(self):

        print('My name is %s.' % self.name)

然后

callable(Student())

显示 TypeError:__init__() missing 1 required positional argument : 'name'

如果改成 

class Student(object):

    def __init__(self, name='a'):

        self.name = name

    def __call__(self):

        print('My name is %s.' % self.name)

然后

callable(Student())

显示 True


  • 1

Reply