private = &39:
;python2
coding: utf-8
def deco(f);
for i in xrange(5);
@deco
def simple();a simple2 fun"., private[0]
f()
private[0] += 1
return wrap
@deco
def simple()def func():
print &39.
是下面代码的简写
func = deco(func)
这就是装饰器做的事情
[0]
private = 0
a simple fun
private = 1
a simple fun
private = 2
a simple fun
private = 3
a simple fun
private = 4
a simple fun
[0]
private = 0
a simple2 fun
private = 1
a simple2 fun
private = 2
a simple2 fun
private = 3
a simple2 fun
private = 4
a simple2 fun
复制代码
.;bin&47;a simple fun"!&47:
print ":
.:
simple()
def simple2():
print "usr&47.:
private = [0]
print private
wrap 是一个closure
def wrap().
shmilyflying 2018-11-19 05:24:28