Lesson text used to use self incorrectly

the syntax in the lesson for super is the following:

class Sink:
def init(self, basin, nozzle):
self.basin = basin
self.nozzle = nozzle

class KitchenSink(Sink):
def init(self, basin, nozzle, trash_compactor=None):
super().init(self, basin, nozzle)
if trash_compactor:
self.trash_compactor = trash_compactor

and again points out the syntax again:

super().init(self, basin, nozzle)

However, I was surprised to see “self” in the super() syntax from other videos I watched about it. When I followed the syntax the error I got was:

Did you call super().__init__(potatoes, celery, onions) ?

Without the self as a part of it. So is there a reason or is this an error?

[quote=“monochromaticmau, post:2, topic:373200”]
However, I was surprised to see “self” in the super() syntax from other videos I watched about it.

came here to ask the same thing

2 Likes

@monochromaticmau @gstek
I guess, there is something wrong with the instructions. As, I tried running code which was in instructions as an example, I got same error.
So, after that I checked out the syntax of super() in python official documentation, and found out -
1) Syntax of super() in python 3 is
class ParentClass():
def __ init __(self, a, b):
pass

class ChildClass(ParentClass):
def __ init __ (self, a, b, c, d):
super(). __ init __ (a, b)
self.c = c
self.d = d

2) Syntax of super() in python 2 is
class ParentClass():
def __ init __(self, a, b):
pass

class ChildClass(ParentClass):
def __ init __ (self, a, b, c, d):
super(ChildClass, self). __ init __(a, b)
self.c = c
self.d = d

Follow 1st syntax, you will not get any error.
Hope these helps.

7 Likes

Thanks for verifying that @abhijeet_shettiwar, I didn’t realize it was a Python 2 v Python 3 issues. Hope they fix that or at least make mention of it in the instructions.

1 Like

This is the solution to the excercise fgiven by codeacademy:
class PotatoSalad:
def init(self, potatoes, celery, onions):
self.potatoes = potatoes
self.celery = celery
self.onions = onions

class SpecialPotatoSalad(PotatoSalad):
def init(self, potatoes, celery, onions):
super().init(potatoes, celery, onions)
self.raisins = 40

why raisins are not added to the method init() like that: def init(self, potatoes, celery, onions, raising):
self.raisins = 40

4 Likes

I’d also like to know that.

1 Like