标签:var user span turn 顺序 调用 for before bcf
1.调用装饰器
def outer(func):
def inter():
print("log")
return func()
return inter()
@outer
def f1():
print("F1")
@outer
def f2():
print("F2")
执行结果
log
F1
log
F2
2.
def outer(func):
print(123)
return func()
@outer
def f1():
print("F1")
执行结果
123
F1
3.
def f1():
print(‘123‘)
def f2(xxx):
xxx()
f2(f1)
执行结果
123
4.调整顺序
def outer (func):
def inter():
print("log")
ret = func()
print("after")
return ret
return inter()
@outer
def f1():
print("F1")
执行结果
log
F1
after
5.
def outer(func):
def inter():
print("bcforc")
func()
print("after")
return inter()
@outer
def f1():
print("F1")
执行结果
bcforc
F1
after
6.传参数 :调用时也要建参数
def outer(func):
def inter(a):
r = func(a)
print("asd")
return r
return inter
@outer
def f1(arg):
print(arg)
print("sdf")
return "砍你"
f1(123)
7.传万能参数
def outer(func):
def inter(*args, **kwargs):
print("before")
r = func(*args, **kwargs)
print("asfd")
return r
return inter
@outer
def f1(arg):
print(arg)
return "砍你"
@outer
def f2(rg,kk):
print(rg)
return "砍你"
调用 :文件名han.py
import han
ret = han.f1("sd")
print(ret)
8.
login_user = {"is_login": False }
def outer(func):
def inter(*args, **kvargs):
if login_user["ls_login"]:
r = func()
return r
else:
print("请登录:")
return inter()
@outer
def order():
print("欢迎%s登录" %login_user["curent_user"])
标签:var user span turn 顺序 调用 for before bcf
原文地址:http://www.cnblogs.com/hanwei999/p/6100047.html