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 __call__(self, name):
        return Chain('%s/%s' % (self.__path, name))

    def __str__(self):
        return self.__path

    __repr__ = __str__


print(Chain().users('michael').repos)

/users/michael/repos


  • 1

Reply