def timefun_arg(pre='hello'):
def timefunc(function):
def inner():
print('10086')
print(pre)
function()
return inner
return timefunc
@timefun_arg('100866666666')
def test():
print('i love u')
test()
# it`s so funny
def w1(func):
mylist = [123,456]
def inner():
kk = input('请输入帐号:')
yy = input('请输入密码:')
if int(kk) == mylist[0]:
if int(yy) == mylist[1]:
print('恭喜您有权限')
func()
else:
print('密码错误')
else:
print('帐号错误')
return inner
def w2(func):
def inner():
print('没在验证信息')
func()
return inner
@w1
def f1():
print('验证完毕,f1---66666')
@w1
def f2():
print('验证完毕,f2---66666')
@w1
# @w2#虽然先显示的是w1的装饰功能,其实先装饰的是w2的功能 over f3=w1(f3=w2(f3)) f3()
def f3():
print('验证完毕,f3---66666')
# a = [f1,f2,f3]
# for i in a:
# i()
f3()
# def func(functionName):
# print('---1-----')
# def func_in(a,b):
# print('----2----')
# functionName(a,b)
# print('----3----')
# return func_in
# @func
# def test(a,b):
# print('---test----a= {}, b = {}'.format(a,b))
# test(11,22)
#参数需要在里面所有被装饰的相同函数名+括号的里面添加相应的参数
#-------------------不定参数------*args,**kwargs-----元祖与字典形式
def func1(functionName):
print('---1-----')
def func_in1(*args,**kwargs):
print('----2----')
functionName(*args,**kwargs)
print('----3----')
return func_in1
@func1
def test1(a,b,c,d):
print('---test----a= {}, b = {},c = {}, d = {}'.format(a,b,c,d))
test1(11,22,33,44)
#--------如果被装饰函数里要return,不能有效,解决方式需在里面kk = func(),再returnkk