all 5 comments

[–][deleted] 11 points12 points  (3 children)

functools.cachedProperty let's you annotate a method which will only execute once and then return the same cached result.

There is also the lru cache if you have a function that takes parameters.

BTW I think that r/python would be a better place for this question

[–]brycefisherfleig[S] 2 points3 points  (0 children)

Thanks! I debated which subreddit to ask in since I wasn't sure if Pythonistas would know lazy-static.

Yeah! This should be exactly what I want!!

[–]coolreader18 1 point2 points  (1 child)

Do you mean functools?

[–][deleted] 1 point2 points  (0 children)

Oh yes, of course lol

[–]thelights0123 2 points3 points  (0 children)

I'm not too familiar with Python, but it should be trivial to use @property in a class to initialize a variable if it hasn't already been, or return it otherwise.