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
To anyone who might be reading this in 2020, this functionality is now available in the funcutils module as part of the standard library as of Python 3.8.
https://docs.python.org/dev/library/functools.html#functools.cached_property
Important to note, classes that define their own __dict__ (or do not define one at all) or use __slots__ might not work as expected. For example, NamedTuple and metaclasses.