Basic misunderstanding on object creation

Ian Kelly ian.g.kelly at gmail.com
Wed May 13 10:55:19 EDT 2015


On Wed, May 13, 2015 at 8:45 AM, andrew cooke <andrew at acooke.org> wrote:
>>>> 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.

You're not returning anything from Foo.__new__, so the result of the
constructor is None.  None.__init__ does nothing.



More information about the Python-list mailing list