擅长:python、mysql、java
<p>我将给你一个基本的概述,你必须做什么来完成这一点。下面是一个接受两个参数并执行函数的decorator。缺少的功能以注释形式显示,请将其添加到:</p>
<pre><code>def log_time(path_to_logfile, interval):
def log(func):
# 'wrap' this puppy up if needed
def wrapped(*args, **kwargs):
# start timing
func(*args, **kwargs)
# stop timing
with open(path_to_logfile, 'a') as f:
pass # functionality
return wrapped
return log
</code></pre>
<p>现在可以修饰函数,输出将用<code>path_to_logfile</code>编写。例如,在这里装饰<code>foo</code>:</p>
^{pr2}$
<p>将接受foo并执行它。您需要<code>time</code>并将内容写入文件。您应该更多地尝试使用装饰器,并阅读它们,一篇关于<a href="https://wiki.python.org/moin/PythonDecorators" rel="nofollow">Decorators exist at the Python Wiki</a>的好文章。在</p>