Would either of the existing solutions work for you? class X: def __init__(self, name): self.name = name
@cached_property def title(self): print("compute title once") return self.name.title() @property @lru_cache def upper(self): print("compute uppper once") return self.name.upper() obj = X("victor") print(obj.title) print(obj.title) print(obj.upper) print(obj.upper) _______________________________________________ Python-Dev mailing list -- python-dev@python.org To unsubscribe send an email to python-dev-le...@python.org https://mail.python.org/mailman3/lists/python-dev.python.org/ Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/4LW5FFI74J6A4FHLUTKWHH3WLWBMXASM/ Code of Conduct: http://python.org/psf/codeofconduct/