擅长:python、mysql、java
<p>可以使用sys模块在windows命令行中使用参数运行Python脚本</p>
<p>使用<strong>python在终端中运行此代码应用程序类型True</strong>启用decorator,禁用decorator<strong>python应用程序类型</strong>或<strong>python应用程序类型错误</strong></p>
<pre><code>import time
import sys
TIMING_ENABLED = True
def newdecorator():
def benchmarking(funct):
def timercheck(*args, **kwarg):
if TIMING_ENABLED:
starttime = time.time()
print("starting time", time.time())
funct(*args, **kwarg)
if TIMING_ENABLED:
print("TOTAL TIME TAKEN ::", time.time()-starttime)
return timercheck
return benchmarking
# passing value to the decorators with arguments
@newdecorator()
def tara():
print("hellow testing")
if __name__ == "__main__":
TIMING_ENABLED = sys.argv[1]
tara()
</code></pre>