I have beeing studying __new__ recently, and I read lots of codes where it use __new__ instead of __init__, some times I think both works, but I don't know why the original author use __new__, to be specific, can someone explain why below codes use __new__ instead of __init__?
case I from here
class MiniSubtest(object):
def __new__(cls, *args, **kargs):
self = super(MiniSubtest, cls).__new__(cls)
ret = None
if args is None:
args = []
try:
ret = self.test(*args, **kargs)
finally:
if hasattr(self, "clean"):
self.clean()
return ret
Aucun commentaire:
Enregistrer un commentaire