相關主題
商品描述
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描述符》是一本全面指南,介紹了創建Python描述符的方法,包括一個可通過pip安裝的名為descriptor_tools的庫,該庫是與本書同步編寫的,並且是GitHub上的開源庫。閱讀本書後,您將對描述符的工作原理有很好的理解,並掌握避免使用描述符時的重要注意事項。
您將學到什麼
- 了解描述符協議
- 掌握屬性訪問以及它如何應用於描述符
- 構建自己的描述符
- 使用描述符存儲屬性
- 創建只讀描述符
- 探索描述符類
- 應用描述符的其他用途
本書適合對象
有經驗的Python編碼人員、程序員和開發人員。