__", cls, *args, **kwargs)
31 return object.__new__(cls)
32
33 f = Foo("Bigberg")
34 print("f", f)
35 print("fname", f.name)
36
37
38 #输出
39
40 here...
41 Mytype __new__ Foo (<class 'object'>,) {'__qualname__': 'Foo', '__init__': <function Foo.__init__ at 0x000002A1968FE8C8>, '__module__': '__main__', '__new__': <function Foo.__new__ at 0x000002A1968FE950>}
42 Mytype __init__ Foo (<class 'object'>,) {'__qualname__': 'Foo', '__init__': <function Foo.__init__ at 0x000002A1968FE8C8>, '__module__': '__main__', '__new__': <function Foo.__new__ at 0x000002A1968FE950>}
43 Mytype __call__ Bigberg
44 Foo __new__ <class '__main__.Foo'>
45 obj <__main__.Foo object at 0x000002A196905898> Bigberg
46 <class '__main__.Foo'>
47 Foo __init__
48 f <__main__.Foo object at 0x000002A196905898>
49 fname Bigberg
View Code
创建过程如下:
4.2 执行顺序
类的生成 调用 顺序依次是 __new__ --> __init__ --> __call__
|