TypeError: object.__init__() takes no parameters

Steven D'Aprano steve+comp.lang.python at pearwood.info
Fri Sep 9 10:33:48 CEST 2011

Thomas Rachel wrote:

> Am 09.09.2011 07:47 schrieb Oliver:
>> class Container(object):
>> """Container to store  a number of non-overlapping rectangles."""
>> def __init__(self, xsize=1200, ysize=800):
>> super(Container, self).__init__(xsize, ysize)
> And this is the nonsense: Container derives from object and tries to
> call its superclass's constructor with 2 parameters - which won't work.

Not nonsense. Merely a backward-incompatible change:

[steve at sylar ~]$ python2.2
Python 2.2.3 (#1, Aug 12 2010, 01:08:27)
[GCC 4.1.2 20070925 (Red Hat 4.1.2-27)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> object("two", "parameters")
<object object at 0x92a43e8>

In Python 2.2, the default object constructor accepts, and ignores, any
parameters. In Python 2.3 on up, that becomes an error.


More information about the Python-list mailing list