装饰器的@怎么用?
def f1(x):
return x*2
def f2(x):
return x*x*x
def new_fn(f):
def fn(x):
print 'call'+f.__name__+'()'
return f(x)
return fn
g1=new_fn(f1)
print g1(5)
比如这段代码,@怎么用?
def f1(x):
return x*2
def f2(x):
return x*x*x
def new_fn(f):
def fn(x):
print 'call'+f.__name__+'()'
return f(x)
return fn
g1=new_fn(f1)
print g1(5)
比如这段代码,@怎么用?
2017-03-24
举报