私は興味深いシナリオに遭遇しましたが、デコレータをPythonで作成しています。以下は私のコードです: - 「obj_userは」飾ら関数の引数として渡された場合、上記のコードに示すようにPythonのデコレータとしてクラス内でstaticmethodを作る方法は?
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)
、私は、チェックする、(クラスの静的メソッドである)デコレータを作成しました。私は機能find_father
を装飾しましたが、次のエラーメッセージが表示されています: - 'staticmethod' object is not callable
。
pythonのデコレータとして上記のような静的ユーティリティメソッドを使用する方法は?
ありがとうございます。
この回答の助けをしていますか? http://stackoverflow.com/a/6412373/4014959 –