Discuss / Python / 带参数的链式调用

带参数的链式调用

Topic source

class Chain(object):

def __init__(self, path=''):
    self.__path = path

def __getattr__(self, item):
    return Chain('{}/{}'.format(self.__path, item))

def __str__(self):
    return self.__path

__repr__ = __str__

def __call__(self, param):
    return Chain('{}/{}'.format(self.__path, param))

  • 1

Reply