时间:2021-07-01 10:21:17 帮助过:39人阅读
看具体的例子:
def __init__(self, *args, **kwargs):
print "init"
super(O, self).__init__(*args, **kwargs)
def __new__(cls, *args, **kwargs):
print "new", cls
return super(O, cls).__new__(cls, *args, **kwargs)
def __call__(self, *args, **kwargs):
print "call"
oo = O()
print "________"
oo()
可不可以重载__init__方法呢?明显不可以,因为__init__之前调用了__new__方法,这时候已经生成了一个对象了,没办法实现单例模式