
عنوان:
Fluent Python
نویسنده:
Luciano Ramalho
انتشارات:
O'Reilly Media
تاریخ انتشار
2022
حجم:
7.8MB
معرفی کتاب:" پایتون روان: برنامهنویسی واضح، مختصر و مؤثر "
وقت خود را صرف تطبیق دادن پایتون با الگوهایی که در زبانهای دیگر آموختهاید نکنید. این کتاب به شما کمک میکند تا ذهنیتی پایتونیک پیدا کرده و با استفاده از قابلیتهای منحصربهفرد نسخه ۳، کدی مدرن، مؤثر و قابل نگهداری بنویسید.
سادگی پایتون باعث میشود خیلی زود بهرهور شوید، اما اغلب این به معنای آن است که از تمام ظرفیتهای زبان استفاده نمیکنید. این ویرایش بهروزشده، با تمرکز بر ایدههای کلیدی پایتون ۳، شما را گامبهگام در مسیر بهرهگیری عمیق از ویژگیهای پیشرفتهی زبان همراهی میکند.
لوچیانو رامالیو، نویسندهی برجسته و مدرسی باتجربه، در این کتاب نهتنها مفاهیم پایهای را آموزش میدهد، بلکه ابزارها و الگوهای پیشرفتهای را نیز معرفی میکند که بهویژه برای توسعهدهندگان باتجربه کاربرد دارد.
ساختار کتاب
این نسخه شامل پنج بخش عمده است که هرکدام مانند یک کتاب مستقل عمل میکنند:
۱. ساختارهای داده
- توابع دنبالهای (sequences)
- دیکشنریها و مجموعهها
- یونیکد و مدیریت رشتهها
- Data classes برای ساختاردهی بهتر داده
۲. توابع بهعنوان اشیاء
- توابع درجهیک و کاربردهای آنها
- type hinting و تایپهای قابل خواندن
- الگوهای طراحی تابعمحور
۳. شیءگرایی پیشرفته
- ترکیب، وراثت و mixinها
- تعریف واسطها و پروتکلها
- Overloading عملگرها و توسعهی APIهای منعطف
۴. کنترل جریان برنامه
- Context managerها و مدیریت منابع
- Generators و coroutineها
- برنامهنویسی ناهمگام (async/await)
- پردازش همزمان با Thread/Process poolها
۵. فرابرنامهنویسی (Metaprogramming)
- Propertyها و توصیفگرها
- Decoratorهای کلاسمحور
- Hookهای کلاس برای سادهسازی متاکلاسها
چرا این کتاب؟
- رویکردی مدرن و کاربردی برای یادگیری مفاهیم پیشرفته پایتون
- مناسب برای توسعهدهندگان باتجربهای که میخواهند پایتون را بهصورت حرفهای و عمیق بیاموزند
- تمرکز ویژه بر نوشتن کدی تمیز، کوتاه، سریع و خوانا با سبک پایتونیک
مناسب چه کسانی است؟
برنامهنویسانی که میخواهند از سطح استفاده اولیه از پایتون فراتر بروند و به درک عمیقی از زبان برسند. این کتاب برای کسانی مناسب است که یا تجربهی اولیه با پایتون دارند یا از دیگر زبانها آمدهاند و حالا میخواهند پایتون را آنطور که باید و شاید یاد بگیرند.
فهرست مطالب
- Preface
- Chapter 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
- Chapter 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
- Chapter 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
- Chapter 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
- Chapter 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
- Chapter 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
- Chapter 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
- Chapter 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
- Chapter 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
- Chapter 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
- Chapter 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
- Chapter 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
- Chapter 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
- Chapter 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
- Chapter 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
- Chapter 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
- Chapter 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
- Chapter 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
- Chapter 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
- Chapter 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
- Chapter 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
- Chapter 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
- Chapter 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
- Chapter 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
- About the Author
مشخصات
نام کتاب
Fluent Python
نویسنده
Luciano Ramalho
انتشارات
O'Reilly Media
تاریخ انتشار
2022
ISBN
9781492056355
تعداد صفحات
1358
زبان
انگلیسی
فرمت
حجم
7.8MB
موضوع
Python Programming;Best Practices in Python;Object-Oriented & Functional Techniques in Python