Aly
Aly

Reputation: 16295

python - accessing superclass attributes

Hi I want to achieve the following in python, however I cant figure out what to replace the line super.a = b with:

class Super:
  def __init__(self):
    self.a = 1

class Sub(Super):
  def method(self, b):
    super.a = b

Upvotes: 20

Views: 23633

Answers (1)

user395760
user395760

Reputation:

An Sub is a Super, i.e. all instances of Sub can be treated exactly like instances of Super. In your case, that means you simply set self.a = b.

Upvotes: 24

Related Questions