我遇到了一个有趣的场景,同时在python中创建装饰器。以下是我的代码: -如何使类中的staticmethod作为装饰器在python中?
class RelationShipSearchMgr(object):
@staticmethod
def user_arg_required(obj_func):
def _inner_func(**kwargs):
if "obj_user" not in kwargs:
raise Exception("required argument obj_user missing")
return obj_func(*tupargs, **kwargs)
return _inner_func
@staticmethod
@user_arg_required
def find_father(**search_params):
return RelationShipSearchMgr.search(Relation.RELATION_FATHER, **search_params)
如上面的代码所示,我创建了一个装饰(这是在类的静态方法),检查,如果“obj_user”作为参数传递给装饰函数传递。我已装饰功能find_father
,但我收到以下错误消息: - 'staticmethod' object is not callable
。
如何使用上面显示的静态工具方法作为python中的装饰器?
在此先感谢。
这是否回答帮助? http://stackoverflow.com/a/6412373/4014959 –