user196264097
user196264097

Reputation: 887

Getting error with python oop with super

I am trying this

In [1]: class Parent:
   ...:     def __init__(self):
   ...:         self.a =10
   ...:         self.b =20
   ...:


In [3]: class NewParent(Parent):
    def __init__self():
        super(NewParent,self).__init__()
        self.c =30
   ...:

When i do this

In [4]: c = NewParent()

In [5]: c
Out[5]: <__main__.NewParent instance at 0x2c98878>

In [6]: c.a
Out[6]: 10

In [7]: c.b
Out[7]: 20

In [8]: c.c

AttributeError Traceback (most recent call last) in () ----> 1 c.c

AttributeError: NewParent instance has no attribute 'c'

Upvotes: 0

Views: 57

Answers (2)

Greg
Greg

Reputation: 5588

class NewParent(Parent):
    def __init__self():
        super(NewParent,self).__init__()
        self.c =30

should be

class NewParent(Parent):
    def __init__(self):
        #Your code here

Upvotes: 0

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798686

You goofed the method declaration on NewParent.

def __init__(self):

Upvotes: 1

Related Questions