Discuss / Python / 关于 GET /users/:user/repos 而写

关于 GET /users/:user/repos 而写

Topic source

没写成__call__调用是因为题目用的users,无另作说明可用其他方法代替,故用特定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 users(self,username):
        return Chain('GET /user/%s'%(username))

    __repr__ = __str__
Chain().users('michael').repos   #GET /user/michael/repos

  • 1

Reply