def stable (value): return lambda *args, **kwargs: value def once_per_object (unstable): """Method decorator. Run only once 'unstable' per instance""" def stabilize (*args, **kwargs): self = args [0] result = unstable (*args, **kwargs) setattr (self, unstable.__name__, stable (result)) return result return stabilize def once (unstable): """Method decorator. Run only once 'unstable'.""" def stabilize (*args, **kwargs): self = args [0] result = unstable (*args, **kwargs) setattr (self.__class__, unstable.__name__, stable (result)) return result return stabilize