TypeError: object.__init__() takes no parameters

Ben Finney ben+python at benfinney.id.au
Fri Sep 9 08:44:37 CEST 2011


Oliver <wildeskraut at googlemail.com> writes:

> let me be honest with you, I am a poor programmer who can only do
> Perl.

I strongly suspect you could do more than that.

Welcome to the Python discussion forum.

> I tried to code a program in Perl, but found that another guy already
> finished this job in Python. Unlucky for me, this guy is now CEO of a
> company, not really interested in supporting his old code.

Then he can hardly complain if someone else re-writes it in their
language of choice, can he? :-)

> C:\Documents and Settings\mhg\Desktop\palcalc>shapes.py
> EE...

This, and the rest of your output, is from the call to ‘unittest.main’,
Python's standard-library module for unit testing.

>   File "C:\Documents and Settings\mhg\Desktop\palcalc\shapes.py", line
> 90, in __init__
>     super(Container, self).__init__(xsize, ysize)
> TypeError: object.__init__() takes no parameters

The ‘super(Container, self)’ call asks for a ‘super’ object representing
the (next) superclass of the type of ‘self’.

In this case, as the error message indicates, the next superclass type
is ‘object’ – the base type of all objects. Also as the error message
indicates, the initialiser for ‘object’ doesn't accept the parameters
being passed.

> 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)
>         self.rect = Rectangle(0, 0, xsize, ysize)
>         self.boxes = []
>         self.last_placement_strategy = 0

So, there's no sense in calling the superclass's ‘__init__’ method with
parameters which won't be accepted because of the function signature.


The next thing to do is to ask about the design of these classes (what
is the intention of this initialiser?). But you say you're entirely new
to it, and that the designer has no interest in it. What are your
options for getting their interest and participating in this thread?

-- 
 \     “I cannot conceive that anybody will require multiplications at |
  `\   the rate of 40,000 or even 4,000 per hour …” —F. H. Wales, 1936 |
_o__)                                                                  |
Ben Finney



More information about the Python-list mailing list