装饰作业

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了装饰作业相关的知识,希望对你有一定的参考价值。

技术分享

1.

import time
def timmer(func):
def wrapper(*arg,**kwargs):
start_time = time.time()
res=func(*arg,**kwargs)
end_time = time.time()
print("运行时间:",end_time-start_time)
return res
return wrapper
@timmer
def my_max(x,y):
time.sleep(1)
max = x if x>y else y
return max

my_max(3,5)
print(my_max(3,5))

技术分享

2.

 

def auth2(auth_type):
def auth(func):
def warpper(*args,**kwargs):
if auth_type == ‘ldap‘:
flag = True
while flag:
with open("lock", "r",encoding="utf8") as f_read, open("account1", "r",encoding="utf8") as f_write:
username = input("input your username:").strip()
r=eval(f_write.read())
if username in r :
m = f_read.read()
f = eval(m)
if f[username] == 3:
print("username is locked")
else:
while flag:
password = input("input your password")
if str(r[username]) == password:
print("successful")
func()
flag = False
break
else:
with open("lock", "w",encoding="utf8") as f_read:
number = int(f[username])
number += 1
f[username] = number
f_read.write(str(f))
if number == 3:
print("lock")
flag = False
else:
print("input right username")
else:
print("other")
return warpper
return auth


@auth2(auth_type=‘ldap‘)
def tell():
print("welcome to oldboy")

tell()



























































以上是关于装饰作业的主要内容,如果未能解决你的问题,请参考以下文章

Thymeleaf 模板 - 有没有办法装饰模板而不是包含模板片段?

动态SQL基础概念复习(Javaweb作业5)

HTML5期末大作业:餐饮美食网站设计——咖啡(10页) HTML+CSS+JavaScript 学生DW网页设计作业成品 web课程设计网页规划与设计 咖啡网页设计 美食餐饮网页设计...(代码片段

python装饰器作业

python之闭包函数 装饰器 作业

装饰作业