Discuss / Python / 输出

输出

Topic source

zhr305

#1 Created at ... [Delete] [Delete and Lock User]
class Chain(object):
    def __init__(self, path=''):
        self.__path = path
    
    def __getattr__(self, t):
        if t == 'users':
            return lambda name: Chain('%s/%s'%(self.__path, name))
        return Chain('%s/%s'%(self.__path, t))

    def __str__(self):
        return self.__path

    __repr__ = __str__

print('github.com', Chain().users('michael').users('michael').branches, sep='')

================输出=============
github.com/michael/michael/branches


  • 1

Reply