没有合适的资源?快使用搜索试试~ 我知道了~
Python Descriptors, 2nd Edition.pdf
需积分: 9 8 下载量 44 浏览量
2019-05-10
17:47:32
上传
评论
收藏 1.06MB PDF 举报
温馨提示
Python Descriptors Understanding and Using the Descriptor Protocol,经典Python图书,2018年最新出版,第二版,清晰文字源生PDF,带目录标签。
资源推荐
资源详情
资源评论









Python Descriptors: Understanding and Using the Descriptor Protocol
ISBN-13 (pbk): 978-1-4842-3726-7 ISBN-13 (electronic): 978-1-4842-3727-4
https://doi.org/10.1007/978-1-4842-3727-4
Library of Congress Control Number: 2018960194
Copyright © 2018 by Jacob Zimmerman
is work is subject to copyright. All rights are reserved by the Publisher, whether the whole or
part of the material is concerned, specically the rights of translation, reprinting, reuse of
illustrations, recitation, broadcasting, reproduction on microlms or in any other physical way,
and transmission or information storage and retrieval, electronic adaptation, computer software,
or by similar or dissimilar methodology now known or hereafter developed.
Trademarked names, logos, and images may appear in this book. Rather than use a trademark
symbol with every occurrence of a trademarked name, logo, or image we use the names, logos,
and images only in an editorial fashion and to the benet of the trademark owner, with no
intention of infringement of the trademark.
e use in this publication of trade names, trademarks, service marks, and similar terms, even if
they are not identied as such, is not to be taken as an expression of opinion as to whether or not
they are subject to proprietary rights.
While the advice and information in this book are believed to be true and accurate at the date of
publication, neither the authors nor the editors nor the publisher can accept any legal
responsibility for any errors or omissions that may be made. e publisher makes no warranty,
express or implied, with respect to the material contained herein.
Managing Director, Apress Media LLC: Welmoed Spahr
Acquisitions Editor: Steve Anglin
Development Editor: Matthew Moodie
Coordinating Editor: Mark Powers
Cover designed by eStudioCalamar
Cover image designed by Freepik (www.freepik.com)
Distributed to the book trade worldwide by Springer Science+Business Media NewYork, 233
Spring Street, 6th Floor, NewYork, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail
orders-ny@springer-sbm.com, or visit www.springeronline.com. Apress Media, LLC is a
California LLC and the sole member (owner) is Springer Science + Business Media Finance Inc
(SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation.
For information on translations, please e-mail editorial@apress.com; for reprint, paperback, or
audio rights, please email bookpermissions@springernature.com.
Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook
versions and licenses are also available for most titles. For more information, reference our Print
and eBook Bulk Sales web page at http://www.apress.com/bulk-sales.
Any source code or other supplementary material referenced by the author in this book is
available to readers on GitHub via the book’s product page, located at www.apress.com/
9781484237267. For more detailed information, please visit http://www.apress.com/
source-code.
Printed on acid-free paper
JacobZimmerman
New York, USA
www.allitebooks.com

iii
Part I: About Descriptors �������������������������������������������������������������1
Chapter 1: What Is aDescriptor? ����������������������������������������������������������3
Data Descriptors versus Non-Data Descriptors ����������������������������������������������������4
The Use of Descriptors by Python �������������������������������������������������������������������������4
Summary���������������������������������������������������������������������������������������������������������������5
Chapter 2: The Descriptor Protocol ������������������������������������������������������7
The __get__(self, instance, owner) Method ����������������������������������������������������������7
The __set__(self, instance, value) Method ��������������������������������������������������������� 8
The __delete__(self, instance) Method �����������������������������������������������������������������9
Summary�������������������������������������������������������������������������������������������������������������10
Chapter 3: What Are Descriptors Good For? ���������������������������������������11
Pros of Python Descriptors����������������������������������������������������������������������������������11
Encapsulation ������������������������������������������������������������������������������������������������11
Reuse of Read/Write Patterns �����������������������������������������������������������������������12
Writing for the Class Level �����������������������������������������������������������������������������13
Table of Contents
About the Author ��������������������������������������������������������������������������������vii
About the Technical Reviewer �������������������������������������������������������������ix
Acknowledgments �������������������������������������������������������������������������������xi
Introduction ���������������������������������������������������������������������������������������xiii
www.allitebooks.com

iv
Cons of Python Descriptors ���������������������������������������������������������������������������������13
Encapsulation ������������������������������������������������������������������������������������������������13
Can Be Difficult To Write ��������������������������������������������������������������������������������14
Additional Objects������������������������������������������������������������������������������������������14
Summary�������������������������������������������������������������������������������������������������������������14
Chapter 4: Descriptors in the Standard Library ����������������������������������15
The property Class ����������������������������������������������������������������������������������������������16
The classmethod Descriptor �������������������������������������������������������������������������������18
The staticmethod Descriptor �������������������������������������������������������������������������������19
Regular Methods ������������������������������������������������������������������������������������������������� 19
Summary�������������������������������������������������������������������������������������������������������������20
Chapter 5: Attribute Access and Descriptors �������������������������������������21
Instance Access ��������������������������������������������������������������������������������������������������22
Set and Delete Calls �������������������������������������������������������������������������������������������� 27
The Reasoning Behind Data versus Non-Data Descriptors �������������������������������� 28
Summary�������������������������������������������������������������������������������������������������������������28
Part II: Making Descriptors �������������������������������������������������������29
Chapter 6: Which Methods Are Needed? ��������������������������������������������31
When __get__() Is Called Without an instance Argument ����������������������������������32
Raise Exception or Return self ����������������������������������������������������������������������32
“Unbound” Attributes ������������������������������������������������������������������������������������33
Summary�������������������������������������������������������������������������������������������������������������37
Chapter 7: Storing theAttributes��������������������������������������������������������39
Class-Level Storage ��������������������������������������������������������������������������������������������39
Storing Data on the Descriptor ����������������������������������������������������������������������������40
Storing on the Instance Dictionary ����������������������������������������������������������������46
TABLE OF CONTENTSTABLE OF CONTENTS
www.allitebooks.com
剩余100页未读,继续阅读
资源评论


no1hero
- 粉丝: 3
- 资源: 45
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助


最新资源
- Oracle19c dbca.rsp
- Oracle19c netca.rsp
- 建模大赛:数学与跨学科融合的竞技平台及其意义和影响
- 使用C语言编程设计实现的西工大数据结构实验4源代码
- YOLO编程:解析计算机视觉中的实时目标检测算法及其应用领域
- 5bfc92d3ab69ab29fe0ead7a74b2754d.jpg
- winform+mysql学生管理系统
- anaconda安装,最新超详细版
- 用户兴趣建模大赛 top10 开源代码
- vmware虚拟机安装教程详解.zip
- python编程与YOLO算法组成的坐姿检测系统
- 算法竞赛 C++ 蓝桥杯备赛全攻略 竞赛指导与真题解析
- Python 学习、笔试面试题解析等
- 使用mingw编译的openssl-3.4.1,有需要的自取吧
- 论坛环境搭建和cms过期后台搭建
- Mips 处理器仿真设计
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈



安全验证
文档复制为VIP权益,开通VIP直接复制
