Nicht aus der Schweiz? Besuchen Sie lehmanns.de
Python Descriptors - Jacob Zimmerman

Python Descriptors (eBook)

(Autor)

eBook Download: PDF
2016 | 1st ed.
XV, 64 Seiten
Apress (Verlag)
978-1-4842-2505-9 (ISBN)
Systemvoraussetzungen
16,99 inkl. MwSt
(CHF 16,60)
Der eBook-Verkauf erfolgt durch die Lehmanns Media GmbH (Berlin) zum Preis in Euro inkl. MwSt.
  • Download sofort lieferbar
  • Zahlungsarten anzeigen
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 protocol
What is attribute access and how they apply to descriptors
How to make descriptors and why
Which Methods are needed
How to store attributes
How to do Read-Only Descriptors and Writing _delete()
How to explore the descriptor classes
How 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.

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.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.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 workingwith them.What You Will LearnDiscover descriptor protocolsMaster attribute access and how it applies to descriptorsMake descriptors and discover why you shouldStore attributesCreate read-only descriptors and _delete()Explore the descriptor classesApply the other uses of descriptors and moreWho This Book Is ForExperienced Python coders, programmers and developers.

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

Contents at a Glance 4
Contents 6
About the Author 10
About the Technical Reviewer 11
Acknowledgments 12
Introduction 13
Part I:About Descriptors 14
Chapter 1: What Is a Descriptor? 15
Data Descriptors vs. Nondata Descriptors 15
The Use of Descriptors by Python 16
Summary 16
Chapter 2: The Descriptor Protocol 17
__get__(self, instance, owner) 17
__set__(self, instance, value) 18
__delete__(self, instance) 18
Summary 18
Chapter 3: What Are Descriptors Good For? 19
Data Encapsulation 19
Reuse of Read/Write Patterns 19
Lazy Instantiation 19
Validation 19
Writing for the Class Level 20
Hiding Function Calls Within Attribute Access 20
Triggering Actions 20
Summary 20
Chapter 4: Descriptors in the Standard Library 21
property 21
classmethod 23
staticmethod 24
Regular Methods 24
Summary 25
Chapter 5: Attribute Access and Descriptors 26
Instance Access 26
Class Access 29
Set and Delete Calls 31
The Reasoning Behind Data vs. Nondata Descriptors 31
Summary 32
Part II:Making Descriptors 33
Chapter 6: Which Methods Are Needed? 34
When __get__( ) Is Called Without instance 34
Raise Exception or Return self 35
Unbound Attributes 35
Summary 37
Chapter 7: Storing the Attributes 38
Class-Level Storage 38
Storing Data on the Descriptor 39
Storing on the Instance Dictionary 42
Asking for the Location 44
Set-it-and-forget-it Descriptors 45
Indirectly Asking for the Location 45
Name Mangling 46
Fetching the Name 46
Keying on the ID 47
Letting the User Take Care of It 48
Metadescriptors 49
Summary 49
Chapter 8: Read-Only Descriptors 50
Set-Once Descriptors 50
Secret-Set Descriptors 51
Forced-Set Descriptors 51
Class Constants 52
Summary 54
Chapter 9: Writing __delete__() 55
Summary 55
Chapter 10: Descriptors are Classes Too 56
Inheritance 56
More Methods 56
Optional/Default Parameters 57
Descriptors on Descriptors 57
Passing an Instance Around 57
Descriptors Just Abstract Method Calls 57
Summary 58
Chapter 11: Reusing the Wheel 59
Storage Solutions 59
Read-Only Solutions 61
Simple Unbound Attributes 62
Summary 63
Chapter 12: Other Uses of Descriptors in the World 64
SQLAlchemy4 64
Jigna 64
Elk 65
Validators 65
Summary 65
Bibliography 66
Index 67

Erscheint lt. Verlag 7.12.2016
Zusatzinfo XV, 64 p. 5 illus., 4 illus. in color.
Verlagsort Berkeley
Sprache englisch
Themenwelt Informatik Programmiersprachen / -werkzeuge Python
Schlagworte Coding • descriptors • programming • Python • Software • Standard Library
ISBN-10 1-4842-2505-8 / 1484225058
ISBN-13 978-1-4842-2505-9 / 9781484225059
Haben Sie eine Frage zum Produkt?
PDFPDF (Wasserzeichen)
Größe: 1,3 MB

DRM: Digitales Wasserzeichen
Dieses eBook enthält ein digitales Wasser­zeichen und ist damit für Sie persona­lisiert. Bei einer missbräuch­lichen Weiter­gabe des eBooks an Dritte ist eine Rück­ver­folgung an die Quelle möglich.

Dateiformat: PDF (Portable Document Format)
Mit einem festen Seiten­layout eignet sich die PDF besonders für Fach­bücher mit Spalten, Tabellen und Abbild­ungen. Eine PDF kann auf fast allen Geräten ange­zeigt werden, ist aber für kleine Displays (Smart­phone, eReader) nur einge­schränkt geeignet.

Systemvoraussetzungen:
PC/Mac: Mit einem PC oder Mac können Sie dieses eBook lesen. Sie benötigen dafür einen PDF-Viewer - z.B. den Adobe Reader oder Adobe Digital Editions.
eReader: Dieses eBook kann mit (fast) allen eBook-Readern gelesen werden. Mit dem amazon-Kindle ist es aber nicht kompatibel.
Smartphone/Tablet: Egal ob Apple oder Android, dieses eBook können Sie lesen. Sie benötigen dafür einen PDF-Viewer - z.B. die kostenlose Adobe Digital Editions-App.

Zusätzliches Feature: Online Lesen
Dieses eBook können Sie zusätzlich zum Download auch online im Webbrowser lesen.

Buying eBooks from abroad
For tax law reasons we can sell eBooks just within Germany and Switzerland. Regrettably we cannot fulfill eBook-orders from other countries.

Mehr entdecken
aus dem Bereich
ein kompakter Einstieg für die Praxis

von Ralph Steyer

eBook Download (2024)
Springer Vieweg (Verlag)
CHF 34,15
Arbeiten mit NumPy, Matplotlib und Pandas

von Bernd Klein

eBook Download (2023)
Carl Hanser Verlag GmbH & Co. KG
CHF 29,30