流行的Python语言 第2版(影印版)
Luciano Ramalho
出版时间:2022年11月
页数:983
当要查找某个Python特性的详细解释和用法时,这是我的‘必读’书。对于希望建立自己的知识体系的高级初学者来说,这绝对是一本好书。”
一Carol Willing
Python指导委员会成员(2020一2021)
这不是一本寻常的编码书,毫不枯燥,满是经过测试的实用示例,而且幽默十足。我和我的同事通过这本杰作将我们的Python编码提升到了一个新的水平。”
一Maria McKinley
高级软件工程师

别浪费时间让Python去适应你在其他语言中学到的模式。尽管 Python的简单性可迅速提高你的工作效率,但这往往意味着你并未运用该语言所提供的所有特性。通过这本实践指南的更新版,你将学会如何利用最佳理念来编写有效的现代Python3代码。
发现并应用超出你过往经验之外的Python 3惯用特性。作者 Luciano Ramalho将带你了解Python的核心语言特性和库,并教你如何使代码更短、更快、更具可读性。
新版进行了重大的更新,共包含五部分,每部分都相当于一本迷你书:
● 数据结构:序列、字典、集合、Unicode和数据类
● 作为对象的函数:头等函数、相关设计模式和函数声明中的类型提示
● 面向对象的惯用法:组合、继承、mixin、接口、运算符重载、协议和更多静态类型
● 控制流:上下文管理器、生成器、协程、async/await和线程/进程池
● 元编程:属性、特性描述符、类装饰器以及替代或简化元类的新类元编程钩子
  1. Preface
  2. Part I. Data Structures
  3. 1. The Python Data Model
  4. What’s New in This Chapter
  5. A Pythonic Card Deck
  6. How Special Methods Are Used
  7. Overview of Special Methods
  8. Why len Is Not a Method
  9. Chapter Summary
  10. Further Reading
  11. 2. An Array of Sequences
  12. What’s New in This Chapter
  13. Overview of Built-In Sequences
  14. List Comprehensions and Generator Expressions
  15. Tuples Are Not Just Immutable Lists
  16. Unpacking Sequences and Iterables
  17. Pattern Matching with Sequences
  18. Slicing
  19. Using + and * with Sequences
  20. list.sort Versus the sorted Built-In
  21. When a List Is Not the Answer
  22. Chapter Summary
  23. Further Reading
  24. 3. Dictionaries and Sets
  25. What’s New in This Chapter
  26. Modern dict Syntax
  27. Pattern Matching with Mappings
  28. Standard API of Mapping Types
  29. Automatic Handling of Missing Keys
  30. Variations of dict
  31. Immutable Mappings
  32. Dictionary Views
  33. Practical Consequences of How dict Works
  34. Set Theory
  35. Practical Consequences of How Sets Work
  36. Set Operations on dict Views
  37. Chapter Summary
  38. Further Reading
  39. 4. Unicode Text Versus Bytes
  40. What’s New in This Chapter
  41. Character Issues
  42. Byte Essentials
  43. Basic Encoders/Decoders
  44. Understanding Encode/Decode Problems
  45. Handling Text Files
  46. Normalizing Unicode for Reliable Comparisons
  47. Sorting Unicode Text
  48. The Unicode Database
  49. Dual-Mode str and bytes APIs
  50. Chapter Summary
  51. Further Reading
  52. 5. Data Class Builders
  53. What’s New in This Chapter
  54. Overview of Data Class Builders
  55. Classic Named Tuples
  56. Typed Named Tuples
  57. Type Hints 101
  58. More About @dataclass
  59. Data Class as a Code Smell
  60. Pattern Matching Class Instances
  61. Chapter Summary
  62. Further Reading
  63. 6. Object References, Mutability, and Recycling
  64. What’s New in This Chapter
  65. Variables Are Not Boxes
  66. Identity, Equality, and Aliases
  67. Copies Are Shallow by Default
  68. Function Parameters as References
  69. del and Garbage Collection
  70. Tricks Python Plays with Immutables
  71. Chapter Summary
  72. Further Reading
  73. Part II. Functions as Objects
  74. 7. Functions as First-Class Objects
  75. What’s New in This Chapter
  76. Treating a Function Like an Object
  77. Higher-Order Functions
  78. Anonymous Functions
  79. The Nine Flavors of Callable Objects
  80. User-Defined Callable Types
  81. From Positional to Keyword-Only Parameters
  82. Packages for Functional Programming
  83. Chapter Summary
  84. Further Reading
  85. 8. Type Hints in Functions
  86. What’s New in This Chapter
  87. About Gradual Typing
  88. Gradual Typing in Practice
  89. Types Are Defined by Supported Operations
  90. Types Usable in Annotations
  91. Annotating Positional Only and Variadic Parameters
  92. Imperfect Typing and Strong Testing
  93. Chapter Summary
  94. Further Reading
  95. 9. Decorators and Closures
  96. What’s New in This Chapter
  97. Decorators 101
  98. When Python Executes Decorators
  99. Registration Decorators
  100. Variable Scope Rules
  101. Closures
  102. The nonlocal Declaration
  103. Implementing a Simple Decorator
  104. Decorators in the Standard Library
  105. Parameterized Decorators
  106. Chapter Summary
  107. Further Reading
  108. 10. Design Patterns with First-Class Functions
  109. What’s New in This Chapter
  110. Case Study: Refactoring Strategy
  111. Decorator-Enhanced Strategy Pattern
  112. The Command Pattern
  113. Chapter Summary
  114. Further Reading
  115. Part III. Classes and Protocols
  116. 11. A Pythonic Object
  117. What’s New in This Chapter
  118. Object Representations
  119. Vector Class Redux
  120. An Alternative Constructor
  121. classmethod Versus staticmethod
  122. Formatted Displays
  123. A Hashable Vector2d
  124. Supporting Positional Pattern Matching
  125. Complete Listing of Vector2d, Version 3
  126. Private and “Protected” Attributes in Python
  127. Saving Memory with __slots__
  128. Overriding Class Attributes
  129. Chapter Summary
  130. Further Reading
  131. 12. Special Methods for Sequences
  132. What’s New in This Chapter
  133. Vector: A User-Defined Sequence Type
  134. Vector Take #1: Vector2d Compatible
  135. Protocols and Duck Typing
  136. Vector Take #2: A Sliceable Sequence
  137. Vector Take #3: Dynamic Attribute Access
  138. Vector Take #4: Hashing and a Faster ==
  139. Vector Take #5: Formatting
  140. Chapter Summary
  141. Further Reading
  142. 13. Interfaces, Protocols, and ABCs
  143. The Typing Map
  144. What’s New in This Chapter
  145. Two Kinds of Protocols
  146. Programming Ducks
  147. Goose Typing
  148. Static Protocols
  149. Chapter Summary
  150. Further Reading
  151. 14. Inheritance: For Better or for Worse
  152. What’s New in This Chapter
  153. The super() Function
  154. Subclassing Built-In Types Is Tricky
  155. Multiple Inheritance and Method Resolution Order
  156. Mixin Classes
  157. Multiple Inheritance in the Real World
  158. Coping with Inheritance
  159. Chapter Summary
  160. Further Reading
  161. 15. More About Type Hints
  162. What’s New in This Chapter
  163. Overloaded Signatures
  164. TypedDict
  165. Type Casting
  166. Reading Type Hints at Runtime
  167. Implementing a Generic Class
  168. Variance
  169. Implementing a Generic Static Protocol
  170. Chapter Summary
  171. Further Reading
  172. 16. Operator Overloading
  173. What’s New in This Chapter
  174. Operator Overloading 101
  175. Unary Operators
  176. Overloading + for Vector Addition
  177. Overloading * for Scalar Multiplication
  178. Using @ as an Infix Operator
  179. Wrapping-Up Arithmetic Operators
  180. Rich Comparison Operators
  181. Augmented Assignment Operators
  182. Chapter Summary
  183. Further Reading
  184. Part IV. Control Flow
  185. 17. Iterators, Generators, and Classic Coroutines
  186. What’s New in This Chapter
  187. A Sequence of Words
  188. Why Sequences Are Iterable: The iter Function
  189. Iterables Versus Iterators
  190. Sentence Classes with __iter__
  191. Lazy Sentences
  192. When to Use Generator Expressions
  193. An Arithmetic Progression Generator
  194. Generator Functions in the Standard Library
  195. Iterable Reducing Functions
  196. Subgenerators with yield from
  197. Generic Iterable Types
  198. Classic Coroutines
  199. Chapter Summary
  200. Further Reading
  201. 18. with, match, and else Blocks
  202. What’s New in This Chapter
  203. Context Managers and with Blocks
  204. Pattern Matching in lis.py: A Case Study
  205. Do This, Then That: else Blocks Beyond if
  206. Chapter Summary
  207. Further Reading
  208. 19. Concurrency Models in Python
  209. What’s New in This Chapter
  210. The Big Picture
  211. A Bit of Jargon
  212. A Concurrent Hello World
  213. The Real Impact of the GIL
  214. A Homegrown Process Pool
  215. Python in the Multicore World
  216. Chapter Summary
  217. Further Reading
  218. 20. Concurrent Executors
  219. What’s New in This Chapter
  220. Concurrent Web Downloads
  221. Launching Processes with concurrent.futures
  222. Experimenting with Executor.map
  223. Downloads with Progress Display and Error Handling
  224. Chapter Summary
  225. Further Reading
  226. 21. Asynchronous Programming
  227. What’s New in This Chapter
  228. A Few Definitions
  229. An asyncio Example: Probing Domains
  230. New Concept: Awaitable
  231. Downloading with asyncio and HTTPX
  232. Asynchronous Context Managers
  233. Enhancing the asyncio Downloader
  234. Delegating Tasks to Executors
  235. Writing asyncio Servers
  236. Asynchronous Iteration and Asynchronous Iterables
  237. async Beyond asyncio: Curio
  238. Type Hinting Asynchronous Objects
  239. How Async Works and How It Doesn’t
  240. Chapter Summary
  241. Further Reading
  242. Part V. Metaprogramming
  243. 22. Dynamic Attributes and Properties
  244. What’s New in This Chapter
  245. Data Wrangling with Dynamic Attributes
  246. Computed Properties
  247. Using a Property for Attribute Validation
  248. A Proper Look at Properties
  249. Coding a Property Factory
  250. Handling Attribute Deletion
  251. Essential Attributes and Functions for Attribute Handling
  252. Chapter Summary
  253. Further Reading
  254. 23. Attribute Descriptors
  255. What’s New in This Chapter
  256. Descriptor Example: Attribute Validation
  257. Overriding Versus Nonoverriding Descriptors
  258. Methods Are Descriptors
  259. Descriptor Usage Tips
  260. Descriptor Docstring and Overriding Deletion
  261. Chapter Summary
  262. Further Reading
  263. 24. Class Metaprogramming
  264. What’s New in This Chapter
  265. Classes as Objects
  266. type: The Built-In Class Factory
  267. A Class Factory Function
  268. Introducing __init_subclass__
  269. Enhancing Classes with a Class Decorator
  270. What Happens When: Import Time Versus Runtime
  271. Metaclasses 101
  272. A Metaclass Solution for Checked
  273. Metaclasses in the Real World
  274. A Metaclass Hack with __prepare__
  275. Wrapping Up
  276. Chapter Summary
  277. Further Reading
  278. Afterword
  279. Index
书名:流行的Python语言 第2版(影印版)
作者:Luciano Ramalho
国内出版社:东南大学出版社
出版时间:2022年11月
页数:983
书号:978-7-5766-0147-3
原版书书名:Fluent Python, 2e
原版书出版商:O'Reilly Media
Luciano Ramalho
 
卢西亚诺·拉马略(Luciano Ramalho)是Thoughtworks首席咨询师、Python软件基金会成员、巴西知名Python语言学习社区Python Brasil联合创始人。拥有25年Python编程经验,著有编程领域经典作品《流畅的Python》。
 
 
The animal on the cover of Fluent Python is a Namaqua sand lizard (Pedioplanis namaquensis), found throughout Namibia in arid savannah and semi-desert regions.
The Namaqua sand lizard has a black body with four white stripes running down its back, brown legs with white spots, a white belly, and a long, pinkish-brown tail. It is one of the fastest of the lizards active during the day and feeds on small insects. It inhabits sparsely vegetated sand gravel flats. Female Namaqua sand lizards lay between three to five eggs in November, and these lizards spends the rest of winter dormant in burrows that they dig near the base of bushes.
The current conservation status of the Namaqua sand lizard is of “Least Concern.” Many of the animals on O’Reilly covers are endangered; all of them are important to the world.
购买选项
定价:198.00元
书号:978-7-5766-0147-3
出版社:东南大学出版社