【发布时间】:2014-03-18 20:48:28
【问题描述】:
我在 Python 中有一个类,我需要将其用作装饰器类,但我想在调用它时计算一些东西:
class SomeClass:
counter = 0
@staticmethod
def some_function(a):
"""
-----------------------
Does something
-----------------------
"""
SomeClass.counter += 1
a = a * a
return a
调用后:
a = new_var.some_function(a)
然后如何从装饰器类中获取计数器值?
【问题讨论】:
-
我认为你的意思是变量而不是常量,因为常量不应该改变。
-
SomeClass.constant? -
静态方法不将 self 作为参数。
-
是什么让你的班级成为装饰者?
标签: python class object decorator