python通过点操作符和reduce遍历对象的属性,pythonreduce,class Klass(


class Klass(object):    def __getattr__(self, name):        """        Locate the function with the dotted        attribute.        """        def traverse(parent, child):            if instance(parent, str):                parent = getattr(self, parent)            return getattr(parent, child)        return reduce(traverse, name.split('.'))

评论关闭