python的bind函数

# -*- coding:utf-8 -*-class functor(object): def __init__(self, func, index=0, *args, **kwargs): self._func = func self._index = index self._args = args self._kwargs = kwargs def __call__(self, *args, **kwargs): args = args[:self._index] + self._args + args[self._index:] kwargs = kwargs.copy() kwargs.update(self._kwargs) return self._func(*args, **kwargs) def bind(func, index=0, *args, **kwargs): return functor(func, index, *args, **kwargs)

Posted in 未分类

发表评论