首页 > 代码库 > 装饰作业
装饰作业
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()
装饰作业
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。