Using property as a decorator
In the preceding section, we looked at how to use property
as a function to modify the properties of an attribute in a class. In this section, we will look at how to use property
as a decorator. Let’s consider the same TestPropertyClass
as in the preceding example and modify the class definition to use the @property
decorator statement instead of the property()
function statement. Refer to the following code:
class TestPropertyClass:
def __init__(self):
self._test_attr = None
@property
def test_attr(self):
return self.test_attr
@test_attr.getter
def test_attr(self):
print("get test_attr")
return self...