I searched quite a bit on this, but can't seem to find anything specific to my problem.
Say I have three separate python files fileA.py, fileB.py, and fileMain.py
fileB.py inherits from fileA.py.
fileA.py
class Parent():
def __init__(self):
self.valueA = 5
fileB.py
from fileA import Parent
class Child(Parent):
def __init__(self):
Parent.__init__():
self.valueB = 10
def Calculate(self):
self.result = self.valueB + self.valueA
print(self.result)
And in fileMain.py I have some code that calls upon the Calculate method in the Child class AFTER valueA in the Parent class has been changed.
from fileA import Parent
from fileB import Child
class MainProgram():
def __init__(self):
self.parent = Parent()
self.child = Child()
self.parent.valueA = 8
self.child.Calculate()
foobar=MainProgram()
My problem is, that the printed output is 15 and not 18. Why? How could I resolve this to get the expected result?
The reason I want for fileB.py to inherit from fileA.py is that I plan on having a fileC.py also inherit from fileA.py and have other calculations done there also using self.valueA. The valueA is supposed to be set by the user of the program. I simplified things here. Hope this makes sense?
Sorry if my use of terminology is wrong. Please correct me. :)