Is there any way to get this to work?
class A:
def method(self):
x = 5
y = 2
method.z = x * y
class B(A):
def method(self):
super().method()
z = super().method().z
xyz = 2**z
def main():
a = A().method()
b = B().method()
main()
Running it gives
NameError: name 'method' is not defined
The idea is that the super class does preliminary work that all subclasses would need to perform, and passes the result on to the subclass for use (in this case z
).
Because the data is only needed in the scope of the subclass method calls, it doesn't make sense to store it in the scope of the class as an instance variable.
The above code is using notation found here, in search of C static function variables in python.