Skip to content
Advertisement

Tag: lazy-initialization

Lazy class attribute initialization

I have a class that takes only one input argument. This value will then be used to compute a number of attributes (only one in the following example). What is a pythonic way if I wanted to take the computation place only if I call the attribute. In addition, the result should be cached and attr2 must not be set

Advertisement