7METHODS AND DECORATORS

image

Python’s decorators are a handy way to modify functions. Decorators were first introduced in Python 2.2, with the classmethod() and staticmethod() decorators, but were overhauled to become more flexible and readable. Along with these two original decorators, Python now provides a few right out of the box and supports the simple creation of custom decorators. But it seems as though most developers do not understand how they work behind the scenes.

This chapter aims to change that—we’ll cover what a decorator is and how to use it, as well as how to create your own decorators. Then we’ll look at using decorators to create ...

Get Serious Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.