5 ms·
In this particular case you should initialize self._kdtree to None in __init__, and just check if self._kdtree is None: <calculate>
by scrollaway 11y ago
In this particular case you should initialize self._kdtree to None in __init__, and just check if self._kdtree is None: <calculate>
- jjgreen 11y agoAh, nice, thanks
- craigds 11y agoWorks great unless None is a valid value for the thing, in which case you'll recalculate it every time. If that was the case you should just use hasattr().
- rbanffy 11y agoOr try and except AttributeError. Exceptions are a good thing.
- jjgreen 11y agoI went with this decorator in the end, works a treat! https://github.com/jjgreen/mvpoly/blob/master/src/python/mvpoly/util/cached_property.py https://github.com/jjgreen/mvpoly/blob/master/src/python/mvp...