python functools

# 工具函数
import functools

print(dir(functools))


# partial函数(偏函数)
def showarg(*args,**kw):
print(args)
print(kw)

p1 = functools.partial(showarg,1,2,3)
p1()
p1(4,5,6)
p1(a='python',b='itcast')


p2 = functools.partial(showarg,a=3,b='Linux')
p2()
p2(1,2)


# wraps函数
def note(func):
"note function"
@functools.wraps(func)
def wrapper():
"wrapper function"
print("note something")
return func()
return wrapper

@note
def test():
"test function"
print("i am test")


print(help(test))
# test()
# test function
# None

posted @ 2018-08-13 13:59  红尘陌上,独自行走  阅读(120)  评论(0编辑  收藏  举报