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.
One possible answer from guido's post (thanks @fraca7):
Any other similar answers?
I'm accepting this answer as a 'yes' to my own question:
Yes, unlike
__new__
, actions that you put in the__init__
method will not be performed during the unpickling process.__new__
cannot make this distinction.