标签:style os ar sp c on log 代码 r
?代码:
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 print Chain().login.user.password
输出:
/login/user/password
备注与说明:
Chain().login.user.password
等价于以下任意一行语句
Chain("/login").user.password Chain("/login/user").password Chain("/login/user/password")
标签:style os ar sp c on log 代码 r
原文地址:http://my.oschina.net/Xwoder/blog/323756