python作业(12.12)
6.
现有以下函数,利用装饰器为此函数加上认证功能,也就是只有用户名为'python', 密码为'123'才能调用此函数,否则不允许
def my_log(name):
print('%s欢迎登陆'%(name))
import functools
def decorator(l):
@functools.wraps(l)
def wrapper(*a, **k):
global uesr
passwd = (input('请输入密码: '))
if user == 'python' and passwd == '123':
l(*a, **k)
else:
print('错误')
return wrapper
@decorator
def my_log(name):
print('%s欢迎登陆:'%(name))
user = (input('请输入用户名:'))
my_log(user)