functools - 功能工具
发布时间
阅读量:
阅读量
翻译自:https://pymotw.com/3/functools/index.html
functools模块提供了调整和扩展函数以及其他 callable objects的工具方法。
装饰器(Decorators)
1)partial函数
partial函数能够对原有函数的默认参数进行调整,并支持添加更多的位置参数或命名参数,无需对原函数进行重新定义,用户只需按照原有函数的调用方式,即可使用经过partial包装后的函数。
import functools
def myfunc(a, b=2):
"Docstring for myfunc()."
print(' called myfunc with:', (a, b))
def show_details(name, f, is_partial=False):
"Show details of a callable object."
print('{}:'.format(name))
print(' object:', f)
if not is_partial:
print(' __name__:', f.__name__)
if is_parti
全部评论 (0)
还没有任何评论哟~
