October 2018
Beginner to intermediate
466 pages
12h 2m
English
If you've never used Python decorators before, you might want to skip this section and come back to it after we've discussed the decorator pattern in Chapter 10, Python Design Patterns I. However, you don't need to understand what's going on to use the decorator syntax in order to make property methods more readable.
The property function can be used with the decorator syntax to turn a get function into a property function, as follows:
class Foo:
@property
def foo(self):
return "bar"
This applies the property function as a decorator, and is equivalent to the previous foo = property(foo) syntax. The main difference, from a readability perspective, is that we get to mark the foo function as a ...