Discuss / Python / 替换usr,编译通过

替换usr,编译通过

Topic source

class Chain(object):

def __init__(self, path=''):
    self._path = path

def __getattr__(self, path):
    if path == 'usr':
        return lambda usrname : Chain('%s/:%s' % (self._path, usrname))
    else:
        return Chain('%s/%s' % (self._path, path))

def __str__(self):
    return self._path

__repr__ = __str__

如题


  • 1

Reply