【发布时间】:2015-01-26 09:08:17
【问题描述】:
我在 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
【问题讨论】:
标签: python static-methods evaluation-strategy