'''f.__name__
f.__doc__
f.__module__ 所属模块
f.__defaults__ 默认参数
f.__closure__ 闭包'''
import functools
def f(a, b = 1, c = []):
'''func for print abc'''
print a, b, c
return
def f_():
a =
2
b =
10
c =
100
return lambda k: a ** k + b
def mydecorator(func):
@functools.wraps(func) # 新添加的一行
def wrapper(*args, **kargs):
'''wrapper function'''
print 'IN wrapper'
func(*args, **kargs)
return wrapper
@mydecorator
def example():
'''example function'''
print 'IN example'
if __name__ ==
'__main__':
print f.__name__
print f.__doc__
print f.__module__
print f.__defaults__
print f.__closure__
f.__defaults__[
1].append(
'abc')
f(
100)
print f.__defaults__
p = f
print p.__name__
print '*' *
30
print f_.__closure__
g = f_()
print g.__closure__
c = g.__closure__[
2]
print c.cell_contents
print '*' *
30
print g(
10)
转载请注明原文地址: https://ju.6miu.com/read-150332.html