0
Why not __new__ gets called before __init__ ?
As I read in object lifecycle topic, that __new__ method occurs just before instantiation. But when I run below code, I always get printed "init calling", not getting printed "new calling" before "init calling". Why? class ABC: def __init__(self): print("init calling") def __new__(self): print("new calling") def __call__(self): print("call calling") a = ABC()
3 Antworten
+ 1
where u read that?
0
Just few minutes ago. https://www.sololearn.com/Play/JUMP_LINK__&&__python__&&__JUMP_LINK
0
If you want to control creating your object, you need write your own code, which creates the object (using super) and then return it. Your __new__ does not create object.
https://stackoverflow.com/questions/674304/why-is-init-always-called-after-new