I\'m writing a class in python and I have an attribute that will take a relatively long time to compute, so I only want to do it once. Also, it will not be
The dickens package (not mine) offers cachedproperty, classproperty and cachedclassproperty decorators.
cachedproperty
classproperty
cachedclassproperty
To cache a class property:
from descriptors import cachedclassproperty class MyClass: @cachedclassproperty def approx_pi(cls): return 22 / 7