Zimmerman | Python Descriptors | E-Book | www2.sack.de
E-Book

E-Book, Englisch, 68 Seiten

Zimmerman Python Descriptors


1. ed
ISBN: 978-1-4842-2505-9
Verlag: Apress
Format: PDF
Kopierschutz: 1 - PDF Watermark

E-Book, Englisch, 68 Seiten

ISBN: 978-1-4842-2505-9
Verlag: Apress
Format: PDF
Kopierschutz: 1 - PDF Watermark



This short book on Python descriptors is a collection of knowledge and ideas from many sources on dealing with and creating descriptors. And, after going through the things all descriptors have in common, the author explores ideas that have multiple ways of being implemented as well as completely new ideas never seen elsewhere before.

There aren't many good resources out there for writing Python descriptors, and extremely few books. This is a sad state of affairs, as it makes it difficult for Python developers to get a really good understanding of how descriptors work and the techniques to avoid the big gotchas associated with working with them.
This truly is a comprehensive guide to creating Python descriptors. As a BONUS: A pip install-able library, descriptor_tools, was written alongside this book and is an open source library on GitHub.

What you'll learn:
What is a descriptor protocolWhat is attribute access and how they apply to descriptorsHow to make descriptors and whyWhich Methods are neededHow to store attributesHow to do Read-Only Descriptors and Writing _delete()How to explore the descriptor classesHow to apply the other uses of descriptors and more

Who is this book for:This book is for experienced Python coders, programmers and developers.



Jacob Zimmerman is a certified Java programmer and a Python and Kotlin enthusiast.

Zimmerman Python Descriptors jetzt bestellen!

Autoren/Hrsg.


Weitere Infos & Material


1;Contents at a Glance;4
2;Contents;6
3;About the Author;10
4;About the Technical Reviewer;11
5;Acknowledgments;12
6;Introduction;13
7;Part I:About Descriptors;14
7.1;Chapter 1: What Is a Descriptor?;15
7.1.1;Data Descriptors vs. Nondata Descriptors;15
7.1.2;The Use of Descriptors by Python;16
7.1.3;Summary;16
7.2;Chapter 2: The Descriptor Protocol;17
7.2.1;__get__(self, instance, owner);17
7.2.2;__set__(self, instance, value);18
7.2.3;__delete__(self, instance);18
7.2.4;Summary;18
7.3;Chapter 3: What Are Descriptors Good For?;19
7.3.1;Data Encapsulation;19
7.3.2;Reuse of Read/Write Patterns;19
7.3.3;Lazy Instantiation;19
7.3.4;Validation;19
7.3.5;Writing for the Class Level;20
7.3.6;Hiding Function Calls Within Attribute Access;20
7.3.7;Triggering Actions;20
7.3.8;Summary;20
7.4;Chapter 4: Descriptors in the Standard Library;21
7.4.1;property;21
7.4.2;classmethod;23
7.4.3;staticmethod;24
7.4.4;Regular Methods;24
7.4.5;Summary;25
7.5;Chapter 5: Attribute Access and Descriptors;26
7.5.1;Instance Access;26
7.5.2;Class Access;29
7.5.3;Set and Delete Calls;31
7.5.4;The Reasoning Behind Data vs. Nondata Descriptors;31
7.5.5;Summary;32
8;Part II:Making Descriptors;33
8.1;Chapter 6: Which Methods Are Needed?;34
8.1.1;When __get__( ) Is Called Without instance;34
8.1.1.1;Raise Exception or Return self;35
8.1.1.2;Unbound Attributes;35
8.1.2;Summary;37
8.2;Chapter 7: Storing the Attributes;38
8.2.1;Class-Level Storage;38
8.2.2;Storing Data on the Descriptor;39
8.2.3;Storing on the Instance Dictionary;42
8.2.3.1;Asking for the Location;44
8.2.3.1.1;Set-it-and-forget-it Descriptors;45
8.2.3.2;Indirectly Asking for the Location;45
8.2.3.2.1;Name Mangling;46
8.2.3.3;Fetching the Name;46
8.2.3.4;Keying on the ID;47
8.2.4;Letting the User Take Care of It;48
8.2.5;Metadescriptors;49
8.2.6;Summary;49
8.3;Chapter 8: Read-Only Descriptors;50
8.3.1;Set-Once Descriptors;50
8.3.2;Secret-Set Descriptors;51
8.3.3;Forced-Set Descriptors;51
8.3.4;Class Constants;52
8.3.5;Summary;54
8.4;Chapter 9: Writing __delete__();55
8.4.1;Summary;55
8.5;Chapter 10: Descriptors are Classes Too;56
8.5.1;Inheritance;56
8.5.2;More Methods;56
8.5.3;Optional/Default Parameters;57
8.5.4;Descriptors on Descriptors;57
8.5.5;Passing an Instance Around;57
8.5.6;Descriptors Just Abstract Method Calls;57
8.5.7;Summary;58
8.6;Chapter 11: Reusing the Wheel;59
8.6.1;Storage Solutions;59
8.6.2;Read-Only Solutions;61
8.6.3;Simple Unbound Attributes;62
8.6.4;Summary;63
8.7;Chapter 12: Other Uses of Descriptors in the World;64
8.7.1;SQLAlchemy4;64
8.7.2;Jigna;64
8.7.3;Elk;65
8.7.4;Validators;65
8.7.5;Summary;65
9;Bibliography;66
10;Index;67



Ihre Fragen, Wünsche oder Anmerkungen
Vorname*
Nachname*
Ihre E-Mail-Adresse*
Kundennr.
Ihre Nachricht*
Lediglich mit * gekennzeichnete Felder sind Pflichtfelder.
Wenn Sie die im Kontaktformular eingegebenen Daten durch Klick auf den nachfolgenden Button übersenden, erklären Sie sich damit einverstanden, dass wir Ihr Angaben für die Beantwortung Ihrer Anfrage verwenden. Selbstverständlich werden Ihre Daten vertraulich behandelt und nicht an Dritte weitergegeben. Sie können der Verwendung Ihrer Daten jederzeit widersprechen. Das Datenhandling bei Sack Fachmedien erklären wir Ihnen in unserer Datenschutzerklärung.