class a:
@HTMLwrapper
def return_stuff_as_html(self, input):
return self.return_stuff(input)
def return_stuff(self, input):
return awesome_dict
は、私は同じことをしたし、それは私のために正常に動作しますが、私はまだ、より良い方法がありますかどうかを知りたいのです: ) - olofom
デコレータが呼び出し可能なものを返すので、関数とメソッドがオブジェクトであるため、デコレータが元のmethを指す装飾されたメソッドに属性を設定できるodですが、my_object_instance.decorated_method.original_method()のような呼び出しは、あいまいであまり明示的ではありません。
>>> import this
The Zen of Python, by Tim Peters
Beautiful 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!
私は待っている間に、ほぼ同じことをしたが、私はちょうどreturnStuffHelperにreturnStuffと改名し、returnStuffを飾ると、その後の呼び出しので、私は、元の関数を変更することが許されませんでした私の関数では代わりにreturnStuffHelper。他のコードでは、HTMLを返すためにreturnStuffが必要です。 – olofom
@olofom:updated –
私はデコレータまたは元のメソッドを変更することはできませんので、それは私にとってはこれよりも良くないと思います。ありがとう:) – olofom