[vtk-developers] Problem with Python "hasattr"

Ben Boeckel ben.boeckel at kitware.com
Sun Aug 9 18:59:11 EDT 2015

On Sun, Aug 09, 2015 at 09:41:25 -0600, David Gobbi wrote:
> https://docs.python.org/2/library/functions.html#hasattr
> This leads to some unexpected behavior in this method from
> dataset_adaptor.py:
>     def __getattr__(self, name):
>         "Forwards unknown attribute requests to VTK array."
>         if not hasattr(self, "VTKObject") or not self.VTKObject:
>             raise AttributeError("class has no attribute %s" % name)
>         return getattr(self.VTKObject, name)

How about:

    def __getattr__(self, name):
        return getattr(self.VTKObject, name)


More information about the vtk-developers mailing list