tem.py
class temp(object):
def __init__(self,name):
self.name = name
def print(self):
print(self.name)
p = temp(10)
p()
这样会报错
但如果重写python 的 内置__call__,就可以实例调用
lass temp(object):
def __init__(self,name):
self.name = name
def print(self):
print(self.name)
def __call__(self)
print('hello,world')
p = temp(10)
p()
samuel@ubuntu:~$ python3 tem.py
hello world