python_装饰器之页面登陆验证
程序员文章站
2022-10-08 21:35:22
import timedef auth(func): def wrapper(*args, **kwargs): username = input('username:').strip() password = input('password:').strip() if username == 'a ......
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()
下一篇: 技术境界的二三四