Discuss / Python / 实现替换

实现替换

Topic source

kingsley_磊

#1 Created at ... [Delete] [Delete and Lock User]
class Chain(object):    def __init__(self, path=''):        self._path = path    def __getattr__(self, path):        if path=='users':            return lambda s: Chain('GET %s/%s' % (self._path, path)+'/:'+s)        return Chain('%s/%s' % (self._path, path))    def __str__(self):        return self._path    __repr__ = __str__# GET /users/:user/reposprint(Chain().users('xulei').repos)

  • 1

Reply