Book Image

Daniel Arbuckle's Mastering Python

By : Daniel Arbuckle
Book Image

Daniel Arbuckle's Mastering Python

By: Daniel Arbuckle

Overview of this book

Daniel Arbuckle's Mastering Python covers the basics of operating in a Python development environment, before moving on to more advanced topics. Daniel presents you with real-world solutions to Python 3.6 and advanced-level concepts, such as reactive programming, microservices, ctypes, and Cython tools. You don't need to be familiar with the Python language to use this book, as Daniel starts with a Python primer. Throughout, Daniel highlights the major aspects of managing your Python development environment, shows you how to handle parallel computation, and helps you to master asynchronous I/O with Python 3.6 to improve performance. Finally, Daniel will teach you the secrets of metaprogramming and unit testing in Python, helping you acquire the perfect skillset to be a Python expert. Daniel will get you up to speed on everything from basic programming practices to high-end tools and techniques, things that will help set you apart as a successful Python programmer.
Table of Contents (13 chapters)

Using function decorators

In this section, we're going to look at one of the most ubiquitous function decorators. We'll see how to construct a decorator, how to use it, and how it works.

The basic definition of a decorator is simple. It's just a function that takes another function as its input, does something with it, and then returns the result of its operations, as shown here:

The return value replaces the original input function, so the changes a decorator can make are potentially quite drastic. A decorator that doesn't change anything at all is a function that accepts one parameter and immediately returns it.

Using the @ syntax in a function decorator

Python has a special syntax for applying a decorator...