python通过点操作符和reduce遍历对象的属性的代码
如下的资料是关于python通过点操作符和reduce遍历对象的属性的内容,应该能对码农们有较大用途。
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('.'))
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。