让我从这开始不重复
为什么__init__如果没有args调用__new__就不会被调用.我试图精心构建了一些示例代码__new__和__init__有没有解释,我可以找到.
基本参数:
__init__方法,反过来调用一个_parse方法_parse子类中的方法super以避免Python日志记录中的问题
:为什么__init__被调用两次?无论如何,__init__应该在之后调用__new__以及为什么下面的一些样本不起作用的每个解释我似乎能够指出其他有用的情况并排除解释.
class NotMine(object):
def __init__(self, *args, **kwargs):
print "NotMine __init__"
self._parse()
def _parse(self):
print "NotMine _parse"
class ABC(NotMine):
def __new__(cls,name,*args, **kwargs):
print "-"*80
print "Entered through the front door ABC.__new__(%s,%s,*%s,**%s)"%(cls,name,args,kwargs)
if name == 'AA':
obj = super(NotMine,ABC).__new__(AA,*args,**kwargs)
print "Exiting door number 1 with an instance of: %s"%type(obj)
return obj
elif …Run Code Online (Sandbox Code Playgroud)