import time def cal_time(func): #计算时间的装饰器 def wrapper(*args,**kwargs): t1 = time.time() res = func(*args,**kwargs) t2 = time.time() print('函数%s运行时间:%s'%(func.__name__,t2 - t1)) return res return wrapper
def home():
print('-------欢迎登录-------')
def america():
print('-------美国专区-------')
user_status = False
def login(s):
def outer(func):
def inner(*arg):
global user_status
if user_status == False:
name = input('用户名..')
pwd = input('密码')
if name == '111' and pwd == '111':
user_status = True
else:
print('账号密码不对')
else:
print('用户已登录,认证通过')
if user_status == True:
func(*arg)
return inner
return outer
login(1)
# @login('qq')
# def henan(style):
# print('-------河南专区-------',style)
# henan('3p')
# xx = login('qq') #xx = 返回outer地址
# henan = xx(henan) # 左边henan = outer(henan),此时左边henan = inner(*arg)执行henan(*arg)
# henan('3p')
user_status = False # 用户登录了就把这个改成True def login(auth_type): #qq def outer(func): #henan def inner(*args,**kwargs): #3p _username = "alex" # 假装这是DB里存的用户信息 _password = "abc!23" # 假装这是DB里存的用户信息 global user_status if user_status == False: username = input("user:") password = input("pasword:") if username == _username and password == _password: print("welcome login....") user_status = True else: print("wrong username or password!") else: print("用户已登录,验证通过...") if user_status: func(*args,*kwargs) #3p return inner return outer def home(): print("---首页----") def america(): print("----欧美专区----") def japan(): print("----日韩专区----") @login('qq') # henan = login('qq')(henan) = inner def henan(style): print("----河南专区----",style)