Python Descriptors: Understanding and Using the Descriptor Protocol
暫譯: Python 描述符:理解與使用描述符協議

Jacob Zimmerman

  • 出版商: Apress
  • 出版日期: 2018-10-09
  • 定價: $1,100
  • 售價: 8.0$880
  • 語言: 英文
  • 頁數: 112
  • 裝訂: Paperback
  • ISBN: 1484237269
  • ISBN-13: 9781484237267
  • 相關分類: Python程式語言
  • 立即出貨 (庫存 < 3)

商品描述

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.
 
 

商品描述(中文翻譯)

建立描述符,並查看如何有效使用描述符的想法和範例。在這本簡短的書中,您將探索描述符的一般概念,深入解釋描述符是什麼、它們如何運作以及如何使用它們。一旦您理解描述符協議的簡單性,作者將深入探討在實踐中使用和創建描述符,提供大量的提示、模式和現實世界的指導。由於描述符本質上是靈活的,您將使用多個範例來說明如何最佳利用它們。

本第二版在各處增加了內容,包括涵蓋 set_name_() 描述符的新材料、新增和改進的流程圖以解釋描述符的內部運作,以及一個全新的章節來處理實例級屬性,這是第一次正確創建描述符的最簡單方法。

雖然簡短,Python Descriptors 是一本全面的指南,介紹如何創建 Python 描述符,包括一個可通過 pip 安裝的庫 descriptor_tools,該庫是與本書一起編寫的,並且是一個開源庫,托管在 GitHub 上。閱讀完這本書後,您將對描述符的運作有堅實的理解,並掌握避免與之相關的重大陷阱的技巧。

您將學到什麼


  • 發現描述符協議

  • 掌握屬性訪問及其如何應用於描述符

  • 構建您自己的描述符

  • 使用描述符來存儲屬性

  • 創建只讀描述符

  • 探索描述符類別

  • 應用描述符的其他用途

本書適合誰

有經驗的 Python 程式設計師、程序員和開發人員。