Skip to Content
Mastering Python 2E - Second Edition
book

Mastering Python 2E - Second Edition

by Rick Hattem
May 2022
Intermediate to advanced
710 pages
16h 41m
English
Packt Publishing
Content preview from Mastering Python 2E - Second Edition

6

Decorators – Enabling Code Reuse by Decorating

In this chapter, you are going to learn about Python decorators. The previous chapters have already shown the usage of a few decorators, but you will now find out more about them. Decorators are essentially function/class wrappers that can be used to modify the input, output, or even the function/class itself before executing it. This type of wrapping can just as easily be achieved by having a separate function that calls the inner function, or via inheriting small feature classes commonly called mixins. As is the case with many Python constructs, decorators are not the only way to reach the goal but are definitely convenient in many cases.

While you can get along fine without knowing too much ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mastering Object-Oriented Python - Second Edition

Mastering Object-Oriented Python - Second Edition

Steven F. Lott

Publisher Resources

ISBN: 9781800207721Supplemental Content