验证功能装饰器


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()

猜你喜欢

转载自www.cnblogs.com/fjy49/p/9212790.html
今日推荐