我在 python 中编写了一个静态方法,它需要时间来计算,但我希望它只计算一次,然后返回计算值。我应该怎么办 ?这是一个示例代码:
class Foo:
@staticmethod
def compute_result():
#some time taking process
Foo.compute_result() # this may take some time to compute but store results
Foo.compute_result() # this method call just return the computed result