TypeError: object.__init__() takes no parameters
Duncan Booth
duncan.booth at invalid.invalid
Fri Sep 9 09:20:54 EDT 2011
Steven D'Aprano <steve+comp.lang.python at pearwood.info> wrote:
> 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 recently than that. It only became an error in 2.6:
[dbooth at localhost ~]$ python2.5 -c "object().__init__(42)"
[dbooth at localhost ~]$ python2.6 -c "object().__init__(42)"
Traceback (most recent call last):
File "<string>", line 1, in <module>
TypeError: object.__init__() takes no parameters
--
Duncan Booth http://kupuguy.blogspot.com
More information about the Python-list
mailing list