验证功能装饰器


def auth_func(func):
    def wrapper(*args, **kwargs):
        # strip() 方法用于移除字符串头尾指定的字符(默认为空格或换行符)或字符序列。
        username = input('用户名:') .strip()
        passwd = input('密码:').strip()
        if username == 'sb' and passwd == '123':
            res = func(*args, **kwargs)
            return res
        else:
            print('用户名密码错误')
    return wrapper

@auth_func
def index():
    print('hello ,wellcome to the index')



index()

posted @ 2018-06-22 11:59  旧时光里的小鱼儿  阅读(88)  评论(0编辑  收藏  举报