I have a class with class variables that should be lazily created. I have a working version for instance variables. How do you implement one for class variables? The following is an example usage.
print(MyDatabase.users) # first call should load the users variable and return value
print(MyDatabase.users) # second call should return the stored value
The first error I got when I tried is AttributeError: type object 'MyDatabase' has no attribute 'users' . Is there a way to catch the error in the class?
@propertieswith a custom getterMyDatabase = _MyDatabase()and then the usage will be same likeMyDatabase.users. The strategy might be easier to maintain than ways using class variable.