擅长:python、mysql、java
<p>确实需要<code>self</code>引用吗?在</p>
<p>更常见的是你会这样做</p>
<pre><code>def enable_video(fn):
'''decorate the test function so it starts the video, runs the test, and stop the video'''
def video_aware_test(self_refrence):
start_video_recorder()
try:
fn()
finally:
stop_video_recorder()
return video_aware_test
</code></pre>
<p>你可以这样运用它:</p>
^{pr2}$
<p>如果由于某种原因,装饰师实际上需要自引用,那么您可以在哪里找到它。这个版本不包括以任何方式配置录像机,为此您将使用类而不是函数修饰符并将配置作为参数传递。在</p>