The __init__() function gets called when object is created.
Is it ok to call an object __init__() function again, after its been created?
instance = cls(p1=1, p2=2)
# some code
instance.__init__(p1=123, p2=234)
# some more code
instance.__init__(p1=23, p2=24)
why would anyone wanna call __init__() on an object that is already created?
good question. i wanna re-initialize the instance’s fields.
It’s fine to call
__init__more than once on an object, as long as__init__is coded with the effect you want to obtain (whatever that may be). A typical case where it happens (so you’d better code__init__appropriately!-) is when your class’s__new__method returns an instance of the class: that does cause__init__to be called on the returned instance (for what might be the second, or twentieth, time, if you keep "recycling" instances via your__new__!-).Some additional guidance can be found here. Multiple calls to init during object initialization