Python Descriptors: Understanding and Using the Descriptor Protocol, 2nd Edition
- Length: 97 pages
- Edition: 2nd ed.
- Language: English
- Publisher: Apress
- Publication Date: 2018-12-13
- ISBN-10: 1484237269
- ISBN-13: 9781484237267
- Sales Rank: #1952669 (See Top 100 Books)
Create descriptors and see ideas and examples of how to use descriptors effectively. In this short book, you’ll explore descriptors in general, with a deep explanation of what descriptors are, how they work, and how they’re used. Once you understand the simplicity of the descriptor protocol, the author delves into using and creating descriptors in practice, with plenty of tips, patterns, and real-world guidance. Because descriptors are inherently flexible, you’ll work with multiple examples illustrating how to best take advantage of them.
This second edition includes additions throughout, including new material covering the set_name_() descriptors, new and improved flowcharts to explain the inner workings of descriptors, and a completely new chapter to address instance-level attributes, the easiest way to create descriptors correctly the first time.
Although brief, Python Descriptors is a comprehensive guide to creating Python descriptors, including a pip install-able library called descriptor_tools, which was written alongside this book and is an open source library on GitHub. After reading this book, you will have a solid understanding of how descriptors work and the techniques to avoid the big gotchas associated with working with them.
What You Will Learn
- Discover descriptor protocols
- Master attribute access and how it applies to descriptors
- Build your own descriptors
- Use descriptors to store attributes
- Create read-only descriptors
- Explore the descriptor classes
- Apply the other uses of descriptors
Who This Book Is For
Experienced Python coders, programmers, and developers.
Table of Contents
Part I: About Descriptors
Chapter 1: What Is a Descriptor?
Chapter 2: The Descriptor Protocol
Chapter 3: What Are Descriptors Good For?
Chapter 4: Descriptors in the Standard Library
Chapter 5: Attribute Access and Descriptors
Part II: Making Descriptors
Chapter 6: Which Methods Are Needed?
Chapter 7: Storing the Attributes
Chapter 8: Read-Only Descriptors
Chapter 9: Writing__delete__()
Chapter 10: Descriptors Are Classes Too
Chapter 11: Reusing the Wheel
Chapter 12: Instance-Level Descriptors
Chapter 13: Other Uses of Descriptors In the World