Well, you can do it this way:<p><pre><code>    def kdtree(self):
        try:
            return self._kdtree
        except AttributeError:
            pass
        self._kdtree = scipy.spatial.KDTree(self.xi.T)
        return self._kdtree
</code></pre>
And, of course, you could do all of that with a decorator.