【python】哪位大侠给解释一下这个例子,关于__new__
class A(object):
def __new__(cls, *args, **kwds):
print "one"
print "A.__new__", args, kwds
return object.__new__(B, *args, **kwds)
def __init__(cls, *args, **kwds):
print "two"
print "A.__init__", args, kwds
class B(object):
def __new__(cls, *args, **kwds):
print "three"
print cls
print B
print "B.__new__", args, kwds
return object.__new__(cls, *args, **kwds)
def __init__(cls, *args, **kwds):
print "four"
print "B.__init__", args, kwds
print A()
print "====================="
print B()
class A(object):
def __new__(cls, *args, **kwds):
print "one"
print "A.__new__", args, kwds
return object.__new__(B, *args, **kwds)
def __init__(cls, *args, **kwds):
print "two"
print "A.__init__", args, kwds
class B(A):
def __new__(cls, *args, **kwds):
print "three"
print cls
print B
print "B.__new__", args, kwds
return A.__new__(cls, *args, **kwds)
def __init__(cls, *args, **kwds):
print "four"
print "B.__init__", args, kwds
print A()
print "====================="
print B()
class A(object):
def __new__(cls, *args, **kwds):
print "one"
print "A.__new__", args, kwds
## return object.__new__(B, *args, **kwds)
def __init__(cls, *args, **kwds):
print "two"
print "A.__init__", args, kwds
class B(A):
def __new__(cls, *args, **kwds):
print "three"
print cls
print B
print "B.__new__", args, kwds
return A.__new__(cls, *args, **kwds)
def __init__(cls, *args, **kwds):
print "four"
print "B.__init__", args, kwds
print A()
print "====================="
print B()