Error trying to use super().__init__
<p>I am fairly new to Python and have taken the code excerpt below from a book I'm working with. </p>

<p>It is listed below <strong>exactly</strong> as it is written and explained in the book but yet it throws the following error:</p>

<pre><code>TypeError: super() takes at least 1 argument (0 given)
</code></pre>

<p>When I try to give <code>super</code> an argument, it tells me it needs to be of type.</p>

<p>I've searched multiple threads and haven't had any luck yet.</p>

<pre><code>class Car():
    """A simple attempt to represent a car"""

    def __init__(self, make, model, year):
        """Initialize attributes to describe a car"""
        self.make = make
        self.model = model
        self.year = year
        self.odometer_reading = 0


    def get_descriptive_name(self):
        """Return a neatly formatted descriptive name."""
        long_name = str(self.year) + ' ' + self.make + ' ' + self.model
        return long_name.title()

class ElectricCar(Car):

    def __init__(self, make, model, year):
        super().__init__(make, model, year)


my_tesla = ElectricCar('tesla', 'model s', 2016)
print(my_tesla.get_descriptive_name())
</code></pre>

<p>You're running Python 2, not Python 3. <a href="https://docs.python.org/2/library/functions.html#super" rel="nofollow">Python 2's <code>super</code></a> requires at least one argument (the type in which this method was defined), and usually two (current type and <code>self</code>). Only <a href="https://docs.python.org/3/library/functions.html#super" rel="nofollow">Python 3's <code>super</code></a> can be called without arguments.</p>

<p>Confirm by adding the following to the top of your script, which will report the actual version you're running under:</p>

<pre><code>import sys

print(sys.version_info)
</code></pre>

<p>Note: Since you're not doing anything in <code>ElectricCar</code>'s <code>__init__</code> aside from delegating to <code>Car</code>'s <code>__init__</code> with the same arguments, you can skip defining <code>__init__</code> for <code>ElectricCar</code> entirely. You only need to override <code>__init__</code> with explicit delegation if initializing <code>ElectricCar</code> involves doing something different from initializing a <code>Car</code>, otherwise, <code>Car</code>s initializer is called automatically when initializing a <code>Car</code> subclass that does not define <code>__init__</code>. As written, you could simplify <code>ElectricCar</code> to:</p>

<pre><code>class ElectricCar(Car):
    pass
</code></pre>

<p>and it would behave identically (it would run slightly faster by avoiding the unnecessary interception and delegation of <code>__init__</code>, that's all).</p>

python inheritance init super