__getattr__接收self、path(属性名)作为参数,不能再接收实际用户名'Michael'作为参数,因此需要另外定义一个可以接收用户名参数的users方法
class Chain(object): def __init__(self, path=''): self._path = path def __getattr__(self,path): return Chain('%s/%s' %(self._path, path)) def users(self, name): return Chain('%s/:%s' %(self._path, name)) def __str__(self): return self._path __repr__ = __str__
Sign in to make a reply
飞侠100
__getattr__接收self、path(属性名)作为参数,不能再接收实际用户名'Michael'作为参数,因此需要另外定义一个可以接收用户名参数的users方法