例如,如果我在装饰,像这样是否可以确定函数是哪种类的方法?
def my_decorator(fn):
# Do something based on the class that fn is a method of
def decorated_fn(*args, **kwargs):
fn(*args, **kwargs)
return decorated_fn
class MyClass(object):
@my_decorator
def my_method(self, param):
print "foo"
的方法是否有可能在my_decorator以确定其中,fn是从哪里来的?
这可能会有所帮助:http://stackoverflow.com/questions/3564049/decorator-changing-function-status-from-method-to-function/3564110#3564110 – carl 2010-10-19 23:36:02