python_装饰器之页面登陆验证

import time


def auth(func):
def wrapper(*args, **kwargs):
username = input('username:').strip()
password = input('password:').strip()
if username == 'admin' and password == '123':
func()
else:
exit()

return wrapper

@auth
def index():
print('index')

@auth
def home():
print('home')

@auth
def bbs():
print('bbs')


# 方法调用
index()
home()
bbs()
点赞