class Chain(object): def __init__(self, path='GET '): self._path = path def __getattr__(self, path): return Chain('%s/%s' % (self._path, path)) def __call__(self,path): return Chain('%s/%s' % (self._path, path)) def __str__(self): return self._path __repr__ = __str__
调用:
Chain().users('michael').repos
输出:
GET /users/michael/repos
厉害啊,
Sign in to make a reply
国风人已变
调用:
输出: