My question is are the following two pieces of code run the same by the interpreter:
class A(object): def __init__(self): self.__x = None @property
Python 3.2 onwards offers a built-in decorator that you can use to create a LRU cache:
@functools.lru_cache(maxsize=128, typed=False)
Alternatively, if you're using Flask / Werkzeug, there's the @cached_property decorator.
For Django, try from django.utils.functional import cached_property
from django.utils.functional import cached_property