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

猜你喜欢

转载自www.cnblogs.com/sklhtml/p/9467677.html