from time import time
class data(object):
def get_data(self):
return self._download_data()
def _download_data(self):
""" download data code """
print("data downloaded")
return time()
class A(data):
def __init__(self):
self.data = self.get_data()
print(self.data)
class B(data):
def __init__(self):
self.data = self.get_data()
print(self.data)
if __name__ == "__main__":
a = A()
b = B()
Result:
data downloaded
1523989483.9526002
data downloaded
1523989483.9536002
You can see the time is different that means the data is not same cause the data is time series data.
In order to get same data, how can be fix?
Also, I knew the following is possible solution but not really at all:
class B(A):
def __init__(self):
self.data = self.get_data()
print(self.data)
Lets say I have class C, D, E... it is not good idea of using class C(B), class D(C), class E(D)...