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()

12th Jul 2018, 1:54 PM
Akshay Babar
Akshay Babar - avatar
3 Respuestas
+ 1
where u read that?
12th Jul 2018, 2:05 PM
$¢𝐎₹𝔭!𝐨𝓝
$¢𝐎₹𝔭!𝐨𝓝 - avatar
12th Jul 2018, 2:22 PM
Akshay Babar
Akshay Babar - avatar
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
12th Jul 2018, 2:37 PM
Микола Федосєєв
Микола Федосєєв - avatar