class a: @HTMLwrapper def return_stuff_as_html(self, input): return self.return_stuff(input) def return_stuff(self, input): return awesome_dict
在等待响应时我做了同样的事情,对我来说很好,但是我仍然想知道是否还有更好的方法:) – olofom
由于在python中,函数和方法是对象,并且由于装饰器返回可调用对象,因此您可以在装饰后的方法上设置指向原始方法的属性,但是像my_object_instance.decorated_method.original_method()之类的调用将较丑陋且不太明确。
>>> import thisThe Zen of Python, by Tim PetersBeautiful is better than ugly.Explicit is better than implicit.Simple is better than complex.Complex is better than complicated.Flat is better than nested.Sparse is better than dense.Readability counts.Special cases aren't special enough to break the rules.Although practicality beats purity.Errors should never pass silently.Unless explicitly silenced.In the face of ambiguity, refuse the temptation to guess.There should be one-- and preferably only one --obvious way to do it.Although that way may not be obvious at first unless you're Dutch.Now is better than never.Although never is often better than *right* now.If the implementation is hard to explain, it's a bad idea.If the implementation is easy to explain, it may be a good idea.Namespaces are one honking great idea -- let's do more of those!



