流行的Python語言 第2版(影印版)
出版時(shí)間:2022年11月
頁數(shù):983
當(dāng)要查找某個(gè)Python特性的詳細(xì)解釋和用法時(shí),這是我的‘必讀’書。對(duì)于希望建立自己的知識(shí)體系的高級(jí)初學(xué)者來說,這絕對(duì)是一本好書?!?br />
一Carol Willing
Python指導(dǎo)委員會(huì)成員(2020一2021)
這不是一本尋常的編碼書,毫不枯燥,滿是經(jīng)過測(cè)試的實(shí)用示例,而且幽默十足。我和我的同事通過這本杰作將我們的Python編碼提升到了一個(gè)新的水平?!?br />
一Maria McKinley
高級(jí)軟件工程師
別浪費(fèi)時(shí)間讓Python去適應(yīng)你在其他語言中學(xué)到的模式。盡管 Python的簡(jiǎn)單性可迅速提高你的工作效率,但這往往意味著你并未運(yùn)用該語言所提供的所有特性。通過這本實(shí)踐指南的更新版,你將學(xué)會(huì)如何利用最佳理念來編寫有效的現(xiàn)代Python3代碼。
發(fā)現(xiàn)并應(yīng)用超出你過往經(jīng)驗(yàn)之外的Python 3慣用特性。作者 Luciano Ramalho將帶你了解Python的核心語言特性和庫,并教你如何使代碼更短、更快、更具可讀性。
新版進(jìn)行了重大的更新,共包含五部分,每部分都相當(dāng)于一本迷你書:
● 數(shù)據(jù)結(jié)構(gòu):序列、字典、集合、Unicode和數(shù)據(jù)類
● 作為對(duì)象的函數(shù):頭等函數(shù)、相關(guān)設(shè)計(jì)模式和函數(shù)聲明中的類型提示
● 面向?qū)ο蟮膽T用法:組合、繼承、mixin、接口、運(yùn)算符重載、協(xié)議和更多靜態(tài)類型
● 控制流:上下文管理器、生成器、協(xié)程、async/await和線程/進(jìn)程池
● 元編程:屬性、特性描述符、類裝飾器以及替代或簡(jiǎn)化元類的新類元編程鉤子
- Preface
- Part I. Data Structures
- 1. The Python Data Model
- What’s New in This Chapter
- A Pythonic Card Deck
- How Special Methods Are Used
- Overview of Special Methods
- Why len Is Not a Method
- Chapter Summary
- Further Reading
- 2. An Array of Sequences
- What’s New in This Chapter
- Overview of Built-In Sequences
- List Comprehensions and Generator Expressions
- Tuples Are Not Just Immutable Lists
- Unpacking Sequences and Iterables
- Pattern Matching with Sequences
- Slicing
- Using + and * with Sequences
- list.sort Versus the sorted Built-In
- When a List Is Not the Answer
- Chapter Summary
- Further Reading
- 3. Dictionaries and Sets
- What’s New in This Chapter
- Modern dict Syntax
- Pattern Matching with Mappings
- Standard API of Mapping Types
- Automatic Handling of Missing Keys
- Variations of dict
- Immutable Mappings
- Dictionary Views
- Practical Consequences of How dict Works
- Set Theory
- Practical Consequences of How Sets Work
- Set Operations on dict Views
- Chapter Summary
- Further Reading
- 4. Unicode Text Versus Bytes
- What’s New in This Chapter
- Character Issues
- Byte Essentials
- Basic Encoders/Decoders
- Understanding Encode/Decode Problems
- Handling Text Files
- Normalizing Unicode for Reliable Comparisons
- Sorting Unicode Text
- The Unicode Database
- Dual-Mode str and bytes APIs
- Chapter Summary
- Further Reading
- 5. Data Class Builders
- What’s New in This Chapter
- Overview of Data Class Builders
- Classic Named Tuples
- Typed Named Tuples
- Type Hints 101
- More About @dataclass
- Data Class as a Code Smell
- Pattern Matching Class Instances
- Chapter Summary
- Further Reading
- 6. Object References, Mutability, and Recycling
- What’s New in This Chapter
- Variables Are Not Boxes
- Identity, Equality, and Aliases
- Copies Are Shallow by Default
- Function Parameters as References
- del and Garbage Collection
- Tricks Python Plays with Immutables
- Chapter Summary
- Further Reading
- Part II. Functions as Objects
- 7. Functions as First-Class Objects
- What’s New in This Chapter
- Treating a Function Like an Object
- Higher-Order Functions
- Anonymous Functions
- The Nine Flavors of Callable Objects
- User-Defined Callable Types
- From Positional to Keyword-Only Parameters
- Packages for Functional Programming
- Chapter Summary
- Further Reading
- 8. Type Hints in Functions
- What’s New in This Chapter
- About Gradual Typing
- Gradual Typing in Practice
- Types Are Defined by Supported Operations
- Types Usable in Annotations
- Annotating Positional Only and Variadic Parameters
- Imperfect Typing and Strong Testing
- Chapter Summary
- Further Reading
- 9. Decorators and Closures
- What’s New in This Chapter
- Decorators 101
- When Python Executes Decorators
- Registration Decorators
- Variable Scope Rules
- Closures
- The nonlocal Declaration
- Implementing a Simple Decorator
- Decorators in the Standard Library
- Parameterized Decorators
- Chapter Summary
- Further Reading
- 10. Design Patterns with First-Class Functions
- What’s New in This Chapter
- Case Study: Refactoring Strategy
- Decorator-Enhanced Strategy Pattern
- The Command Pattern
- Chapter Summary
- Further Reading
- Part III. Classes and Protocols
- 11. A Pythonic Object
- What’s New in This Chapter
- Object Representations
- Vector Class Redux
- An Alternative Constructor
- classmethod Versus staticmethod
- Formatted Displays
- A Hashable Vector2d
- Supporting Positional Pattern Matching
- Complete Listing of Vector2d, Version 3
- Private and “Protected” Attributes in Python
- Saving Memory with __slots__
- Overriding Class Attributes
- Chapter Summary
- Further Reading
- 12. Special Methods for Sequences
- What’s New in This Chapter
- Vector: A User-Defined Sequence Type
- Vector Take #1: Vector2d Compatible
- Protocols and Duck Typing
- Vector Take #2: A Sliceable Sequence
- Vector Take #3: Dynamic Attribute Access
- Vector Take #4: Hashing and a Faster ==
- Vector Take #5: Formatting
- Chapter Summary
- Further Reading
- 13. Interfaces, Protocols, and ABCs
- The Typing Map
- What’s New in This Chapter
- Two Kinds of Protocols
- Programming Ducks
- Goose Typing
- Static Protocols
- Chapter Summary
- Further Reading
- 14. Inheritance: For Better or for Worse
- What’s New in This Chapter
- The super() Function
- Subclassing Built-In Types Is Tricky
- Multiple Inheritance and Method Resolution Order
- Mixin Classes
- Multiple Inheritance in the Real World
- Coping with Inheritance
- Chapter Summary
- Further Reading
- 15. More About Type Hints
- What’s New in This Chapter
- Overloaded Signatures
- TypedDict
- Type Casting
- Reading Type Hints at Runtime
- Implementing a Generic Class
- Variance
- Implementing a Generic Static Protocol
- Chapter Summary
- Further Reading
- 16. Operator Overloading
- What’s New in This Chapter
- Operator Overloading 101
- Unary Operators
- Overloading + for Vector Addition
- Overloading * for Scalar Multiplication
- Using @ as an Infix Operator
- Wrapping-Up Arithmetic Operators
- Rich Comparison Operators
- Augmented Assignment Operators
- Chapter Summary
- Further Reading
- Part IV. Control Flow
- 17. Iterators, Generators, and Classic Coroutines
- What’s New in This Chapter
- A Sequence of Words
- Why Sequences Are Iterable: The iter Function
- Iterables Versus Iterators
- Sentence Classes with __iter__
- Lazy Sentences
- When to Use Generator Expressions
- An Arithmetic Progression Generator
- Generator Functions in the Standard Library
- Iterable Reducing Functions
- Subgenerators with yield from
- Generic Iterable Types
- Classic Coroutines
- Chapter Summary
- Further Reading
- 18. with, match, and else Blocks
- What’s New in This Chapter
- Context Managers and with Blocks
- Pattern Matching in lis.py: A Case Study
- Do This, Then That: else Blocks Beyond if
- Chapter Summary
- Further Reading
- 19. Concurrency Models in Python
- What’s New in This Chapter
- The Big Picture
- A Bit of Jargon
- A Concurrent Hello World
- The Real Impact of the GIL
- A Homegrown Process Pool
- Python in the Multicore World
- Chapter Summary
- Further Reading
- 20. Concurrent Executors
- What’s New in This Chapter
- Concurrent Web Downloads
- Launching Processes with concurrent.futures
- Experimenting with Executor.map
- Downloads with Progress Display and Error Handling
- Chapter Summary
- Further Reading
- 21. Asynchronous Programming
- What’s New in This Chapter
- A Few Definitions
- An asyncio Example: Probing Domains
- New Concept: Awaitable
- Downloading with asyncio and HTTPX
- Asynchronous Context Managers
- Enhancing the asyncio Downloader
- Delegating Tasks to Executors
- Writing asyncio Servers
- Asynchronous Iteration and Asynchronous Iterables
- async Beyond asyncio: Curio
- Type Hinting Asynchronous Objects
- How Async Works and How It Doesn’t
- Chapter Summary
- Further Reading
- Part V. Metaprogramming
- 22. Dynamic Attributes and Properties
- What’s New in This Chapter
- Data Wrangling with Dynamic Attributes
- Computed Properties
- Using a Property for Attribute Validation
- A Proper Look at Properties
- Coding a Property Factory
- Handling Attribute Deletion
- Essential Attributes and Functions for Attribute Handling
- Chapter Summary
- Further Reading
- 23. Attribute Descriptors
- What’s New in This Chapter
- Descriptor Example: Attribute Validation
- Overriding Versus Nonoverriding Descriptors
- Methods Are Descriptors
- Descriptor Usage Tips
- Descriptor Docstring and Overriding Deletion
- Chapter Summary
- Further Reading
- 24. Class Metaprogramming
- What’s New in This Chapter
- Classes as Objects
- type: The Built-In Class Factory
- A Class Factory Function
- Introducing __init_subclass__
- Enhancing Classes with a Class Decorator
- What Happens When: Import Time Versus Runtime
- Metaclasses 101
- A Metaclass Solution for Checked
- Metaclasses in the Real World
- A Metaclass Hack with __prepare__
- Wrapping Up
- Chapter Summary
- Further Reading
- Afterword
- Index
書名:流行的Python語言 第2版(影印版)
國(guó)內(nèi)出版社:東南大學(xué)出版社
出版時(shí)間:2022年11月
頁數(shù):983
書號(hào):978-7-5766-0147-3
原版書書名:Fluent Python, 2e
原版書出版商:O'Reilly Media
Luciano Ramalho
盧西亞諾·拉馬略(Luciano Ramalho)是Thoughtworks首席咨詢師、Python軟件基金會(huì)成員、巴西知名Python語言學(xué)習(xí)社區(qū)Python Brasil聯(lián)合創(chuàng)始人。擁有25年P(guān)ython編程經(jīng)驗(yàn),著有編程領(lǐng)域經(jīng)典作品《流暢的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.