Basic misunderstanding on object creation

andrew cooke andrew at acooke.org
Wed May 13 10:45:31 EDT 2015


> But then nothing will be passed to __init__ on the subclass.
> 
> Andrew

>>> class Foo:
...     def __new__(cls, *args, **kargs):
...         print('new', args, kargs)
...         super().__new__(cls)
... 
>>> class Bar(Foo):
...     def __init__(self, a):
...         print('init', a)
... 
>>> Bar(1)
new (1,) {}

no "init" is printed.



More information about the Python-list mailing list