<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Sun, Aug 9, 2015 at 4:59 PM, Ben Boeckel <span dir="ltr"><<a href="mailto:ben.boeckel@kitware.com" target="_blank">ben.boeckel@kitware.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=""><br>
</span>How about:<br>
<br>
def __getattr__(self, name):<br>
return getattr(self.VTKObject, name)</blockquote><div><br></div><div>If "self" has no "VTKObject" attribute, it immediately goes into infinite recursion.</div><div><br></div><div>The following is the solution that I used. It checks the __dict__ because I know that's where the VTKObject attribute will be kept if it exists.</div><div><br></div><div><div> def __getattr__(self, name):</div><div> try:</div><div> o = self.__dict__["VTKObject"]</div><div> except KeyError:</div><div> o = None</div><div> if o is None:</div><div> raise AttributeError("class has no attribute %s" % name)</div><div> return getattr(o, name)</div></div><div><br></div><div>It could be simplified a bit except that the "VTKObject" attribute can sometimes be set to "None", and it would be confusing if the error message said " 'NoneType' object has no attribute 'name' ".</div><div><br></div><div>The solution would be more complicated than the above if the "VTKObject" of "self" might be kept somewhere other than __dict__, for example if it was an attribute generated by a descriptor in self's type object.</div><div><br></div><div> - David</div>
</div><br></div></div>