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

# 带参数的链式调用

Topic source

永远短毛

#1 Created at ... [Delete] [Delete and Lock User]

class Chain(object): def __init__(self,path=''): self._path=path def __getattr__(self, path): return Chain('%s/%s' % (self._path, path)) def __str__(self): return self._path def __call__(self, name): return Chain('%s/%s' % (self._path, name)) __repr__=__str__ print(Chain().users('Mike').repos)

结果 /users/Mike/repos


  • 1

Reply