목표 : 클래스 메서드를 장식 할 수있게 만듭니다. 클래스 메쏘드가 꾸며지면 사전에 저장되어 다른 클래스 메쏘드가 문자열 메쏘드를 참조 할 수 있습니다.클래스 메서드 및 하위 클래스 메서드에 파이썬 장식 사용
동기 부여 : ASP.Net의 WebMethod와 동일한 기능을 구현하고 싶습니다. 나는 이것을 구글 앱 엔진의 최상위에 놓고있다. 그러나 그것은 내가 가지고있는 어려움의 지점에 영향을 미치지 않는다.
이 일 경우는 어떻게 보일지 :
class UsefulClass(WebmethodBaseClass):
def someMethod(self, blah):
print(blah)
@webmethod
def webby(self, blah):
print(blah)
# the implementation of this class could be completely different, it does not matter
# the only important thing is having access to the web methods defined in sub classes
class WebmethodBaseClass():
def post(self, methodName):
webmethods[methodName]("kapow")
...
a = UsefulClass()
a.post("someMethod") # should error
a.post("webby") # prints "kapow"
이것에 대해 갈 수있는 다른 방법이있을 수 있습니다. 나는 매우 열정적이다.