I want to have a class that is used just for accessing read-only data. If the data is requested from the class but does not exist yet, I want the class to handle getting the data. I'm just wondering if the following code makes sense; can you see any potential issues with this?
class Data:
@property
def some_data(self):
if hasattr(Data, "_some_data"):
return Data._some_data
else:
Data._some_data = function_that_gets_data()
return Data._some_data
# other definitions for more data go here ...
D = Data()
# access data
print(D.some_data)