Home > Backend Development > Python Tutorial > python bind function

python bind function

巴扎黑
Release: 2016-12-09 09:16:59
Original
4169 people have browsed it

# -*- 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)

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template