python多参数多功能多个装饰器
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了python多参数多功能多个装饰器,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1430字,纯文字阅读大概需要3分钟。
内容图文
![python多参数多功能多个装饰器](/upload/InfoBanner/zyjiaocheng/613/e8a521c080e54da1a40bf82a316db0e7.jpg)
下面展示多参数多功能多个装饰器
具体代码如下:
# Author:HY
import time
import math
import sys
def deco(func):
def wrapper(*args,**kwargs):
startt = time.time()
time.sleep(0.00000001)
func(*args,**kwargs)
endt = time.time()
f=str(func)[1:12]
print("The %s runs %s" % (f,(endt - startt)))
return wrapper
def jdt(func):
def wrapper(*args,**kwargs):
func(*args,**kwargs)
for i in range(100):
sys.stdout.write("%s" % i)
sys.stdout.write("% ")
sys.stdout.flush()
time.sleep(0.1)
return wrapper
def defunc(func):
startt=time.time()
func()
endt=time.time()
print("The func runs %s"%(endt-startt))
# return func
@jdt
@deco
def f1(a,b):
print("This is 周长!")
print("C=",2*(a+b))
@deco
def f2(r):
print("This is 面积!")
pai=math.pi
print("S=",pai*r*r)
@deco
def f3(a,b,c):
print("This is 体积!")
print("V=",a*b*c)
f1(1,2)
f2(1)
f3(3,4,5)
输出结果如下:
This is 周长!
C= 6
The function f1 runs 0.0010447502136230469
0% 1% 2% 3% 4% 5% 6% 7% 8% 9% 10% 11% 12% 13% 14% 15% 16% 17% 18% 19% 20% 21% 22% 23% 24% 25% 26% 27% 28% 29% 30% 31% 32% 33% 34% 35% 36% 37% 38% 39% 40% 41% 42% 43% 44% 45% 46% 47% 48% 49% 50% 51% 52% 53% 54% 55% 56% 57% 58% 59% 60% 61% 62% 63% 64% 65% 66% 67% 68% 69% 70% 71% 72% 73% 74% 75% 76% 77% 78% 79% 80% 81% 82% 83% 84% 85% 86% 87% 88% 89% 90% 91% 92% 93% 94% 95% 96% 97% 98% 99% This is 面积!
S= 3.141592653589793
The function f2 runs 0.0019686222076416016
This is 体积!
V= 60
The function f3 runs 0.00160980224609375
Process finished with exit code 0
内容总结
以上是互联网集市为您收集整理的python多参数多功能多个装饰器全部内容,希望文章能够帮你解决python多参数多功能多个装饰器所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。