def wrapper(func):
def inner(*args,**kwargs):
print('主代码前添加的功能')
ret=func(*args,**kwargs)
print('主代码后添加的功能')
return ret
return inner
@wrapper
def func():
print('主代码')
def wrapper(func):
def inner(*args, **kwargs):
username = input('请输入用户名:')
password = input('请输入密码:')
ret = func(username, password)
if ret == '1':
print('登录成功')
else:
print('登录失败')
return ret
return inner
@wrapper
def func(username, password):
if username == 'zhaoruofei' and password == '123':
return '1'
else:
return '2'
func()
wrapper(func)