Dev HelpersOpen library
← Back

Read an attribute lazily with cached_property

Read an attribute lazily with cached_property in Python.

Open this example in the interactive library

Source code

from functools import cached_property
class Report:
    @cached_property
    def title(self):
        print('Computed')
        return 'Summary'
report = Report()
print(report.title, report.title)

Sample output

Computed
Summary Summary