标签:style lazy loading class new img sig UNC 复制
partial对参数进行复制后,会覆盖原有函数的默认值,因为,partial中已经赋值了,默认值就不再生效,如果partial中未定义,则默认值生效
partial定义
def partial(func,*args,**kwargs):
def newfunc(*fargs,**fkwargs):
newkwargs=kwargs.copy()
newkwargs.update(fkwargs)
return func(*(args+fargs),**newkwargs)
newfunc.func=func # 源函数
newfunc.args=args
newfunc.kwargs=kwargs
return newfunc
import functools
import inspect
def cim(x,y:int=8):
print(‘x: {}\ty: {}‘.format(x,y))
print(inspect.signature(cim))
newcim=functools.partial(cim,y=99)
print(inspect.signature(newcim))
newcim(4)
标签:style lazy loading class new img sig UNC 复制
原文地址:https://www.cnblogs.com/dissipate/p/13660497.html