KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I am trying to access a variable from the base class. Here's the parent class: class Parent(object): def __init__(self, value): self.some_var = value And here's the child class: class Child(Parent): def __init__(self, value): super(Child, self).__init__(value) def doSomething(self): parent_var = super(Child, self).some_var Now, if I try to run this code: obj = Child(123) obj.doSomething() I get the following exception: Traceback (most recent call last): File "test.py", line 13, in <module> obj.doSomething() File "test.py", line 10, in doSomething parent_var = super(Child, self).some_var AttributeError: 'super' object has no attribute 'some_var' What am I doing wrong? What is the recommended way to access variables from the base class in Python?
Tags (comma-separated)
Save Edits
Cancel