I understand how both __init__
and __new__
work.
I'm wondering if there is anything __init__
can do that __new__
cannot?
i.e. can use of __init__
be replaced by the following pattern:
class MySubclass(object):
def __new__(cls, *args, **kwargs):
self = super(MySubclass, cls).__new__(cls, *args, **kwargs)
// Do __init__ stuff here
return self
I'm asking as I'd like to make this aspect of Python OO fit better in my head.
See Question&Answers more detail:os