Fluent python clear concise and effective programming

Fluent Python : Clear, Concise, and Effective Programming

Python’s simplicity lets you become productive quickly, but this often means you aren’t using everything it has to offer. With this hands-on guide, you’ll learn how to write effective, idiomatic Python code by leveraging its best—and possibly most neglected—features. Author Luciano Ramalho takes you through Python’s core language features and libraries, and shows you how to make your code shorter, faster, and more readable at the same time.

Many experienced programmers try to bend Python to fit patterns they learned from other languages, and never discover Python features outside of their experience. With this book, those Python programmers will thoroughly learn how to become proficient in Python 3.

  • Python data model: understand how special methods are the key to the consistent behavior of objects
  • Data structures: take full advantage of built-in types, and understand the text vs bytes duality in the Unicode age
  • Functions as objects: view Python functions as first-class objects, and understand how this affects popular design patterns
  • Object-oriented idioms: build classes by learning about references, mutability, interfaces, operator overloading, and multiple inheritance
  • Control flow: leverage context managers, generators, coroutines, and concurrency with the concurrent.futures and asyncio packages
  • Metaprogramming: understand how properties, attribute descriptors, class decorators, and metaclasses work

Источник

Fluent Python

Fluent Python

Read it now on the O’Reilly learning platform with a 10-day free trial.

O’Reilly members get unlimited access to books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.

Book description

Python’s simplicity lets you become productive quickly, but this often means you aren’t using everything it has to offer. With this hands-on guide, you’ll learn how to write effective, idiomatic Python code by leveraging its best—and possibly most neglected—features. Author Luciano Ramalho takes you through Python’s core language features and libraries, and shows you how to make your code shorter, faster, and more readable at the same time.

Many experienced programmers try to bend Python to fit patterns they learned from other languages, and never discover Python features outside of their experience. With this book, those Python programmers will thoroughly learn how to become proficient in Python 3.

  • Python data model: understand how special methods are the key to the consistent behavior of objects
  • Data structures: take full advantage of built-in types, and understand the text vs bytes duality in the Unicode age
  • Functions as objects: view Python functions as first-class objects, and understand how this affects popular design patterns
  • Object-oriented idioms: build classes by learning about references, mutability, interfaces, operator overloading, and multiple inheritance
  • Control flow: leverage context managers, generators, coroutines, and concurrency with the concurrent.futures and asyncio packages
  • Metaprogramming: understand how properties, attribute descriptors, class decorators, and metaclasses work
Читайте также:  Kotlin для начинающих pdf

Publisher resources

Table of contents

  1. Preface
    1. Who This Book Is For
    2. Who This Book Is Not For
    3. How This Book Is Organized
    4. Hands-On Approach
    5. Hardware Used for Timings
    6. Soapbox: My Personal Perspective
    7. Python Jargon
    8. Python Version Covered
    9. Conventions Used in This Book
    10. Using Code Examples
    11. Safari® Books Online
    12. How to Contact Us
    13. Acknowledgments
    1. A Pythonic Card Deck
    2. How Special Methods Are Used
      1. Emulating Numeric Types
      2. String Representation
      3. Arithmetic Operators
      4. Boolean Value of a Custom Type
      1. Overview of Built-In Sequences
      2. List Comprehensions and Generator Expressions
        1. List Comprehensions and Readability
        2. Listcomps Versus map and filter
        3. Cartesian Products
        4. Generator Expressions
        1. Tuples as Records
        2. Tuple Unpacking
        3. Nested Tuple Unpacking
        4. Named Tuples
        5. Tuples as Immutable Lists
        1. Why Slices and Range Exclude the Last Item
        2. Slice Objects
        3. Multidimensional Slicing and Ellipsis
        4. Assigning to Slices
        1. Building Lists of Lists
        1. A += Assignment Puzzler
        1. Searching with bisect
        2. Inserting with bisect.insort
        1. Arrays
        2. Memory Views
        3. NumPy and SciPy
        4. Deques and Other Queues
        1. Generic Mapping Types
        2. dict Comprehensions
        3. Overview of Common Mapping Methods
          1. Handling Missing Keys with setdefault
          1. defaultdict: Another Take on Missing Keys
          2. The __missing__ Method
          1. set Literals
          2. Set Comprehensions
          3. Set Operations
          1. A Performance Experiment
          2. Hash Tables in Dictionaries
          3. Practical Consequences of How dict Works
          4. How Sets Work—Practical Consequences
          1. Character Issues
          2. Byte Essentials
            1. Structs and Memory Views
            1. Coping with UnicodeEncodeError
            2. Coping with UnicodeDecodeError
            3. SyntaxError When Loading Modules with Unexpected Encoding
            4. How to Discover the Encoding of a Byte Sequence
            5. BOM: A Useful Gremlin
            1. Encoding Defaults: A Madhouse
            1. Case Folding
            2. Utility Functions for Normalized Text Matching
            3. Extreme “Normalization”: Taking Out Diacritics
            1. Sorting with the Unicode Collation Algorithm
            1. str Versus bytes in Regular Expressions
            2. str Versus bytes on os Functions
            1. Treating a Function Like an Object
            2. Higher-Order Functions
              1. Modern Replacements for map, filter, and reduce
              1. The operator Module
              2. Freezing Arguments with functools.partial
              1. Case Study: Refactoring Strategy
                1. Classic Strategy
                2. Function-Oriented Strategy
                3. Choosing the Best Strategy: Simple Approach
                4. Finding Strategies in a Module
                1. Decorators 101
                2. When Python Executes Decorators
                3. Decorator-Enhanced Strategy Pattern
                4. Variable Scope Rules
                5. Closures
                6. The nonlocal Declaration
                7. Implementing a Simple Decorator
                  1. How It Works
                  1. Memoization with functools.lru_cache
                  2. Generic Functions with Single Dispatch
                  1. A Parameterized Registration Decorator
                  2. The Parameterized Clock Decorator
                  1. Variables Are Not Boxes
                  2. Identity, Equality, and Aliases
                    1. Choosing Between == and is
                    2. The Relative Immutability of Tuples
                    1. Deep and Shallow Copies of Arbitrary Objects
                    1. Mutable Types as Parameter Defaults: Bad Idea
                    2. Defensive Programming with Mutable Parameters
                    1. The WeakValueDictionary Skit
                    2. Limitations of Weak References
                    1. Object Representations
                    2. Vector Class Redux
                    3. An Alternative Constructor
                    4. classmethod Versus staticmethod
                    5. Formatted Displays
                    6. A Hashable Vector2d
                    7. Private and “Protected” Attributes in Python
                    8. Saving Space with the __slots__ Class Attribute
                      1. The Problems with __slots__
                      1. Vector: A User-Defined Sequence Type
                      2. Vector Take #1: Vector2d Compatible
                      3. Protocols and Duck Typing
                      4. Vector Take #2: A Sliceable Sequence
                        1. How Slicing Works
                        2. A Slice-Aware __getitem__
                        1. Interfaces and Protocols in Python Culture
                        2. Python Digs Sequences
                        3. Monkey-Patching to Implement a Protocol at Runtime
                        4. Alex Martelli’s Waterfowl
                        5. Subclassing an ABC
                        6. ABCs in the Standard Library
                          1. ABCs in collections.abc
                          2. The Numbers Tower of ABCs
                          1. ABC Syntax Details
                          2. Subclassing the Tombola ABC
                          3. A Virtual Subclass of Tombola
                          1. Subclassing Built-In Types Is Tricky
                          2. Multiple Inheritance and Method Resolution Order
                          3. Multiple Inheritance in the Real World
                          4. Coping with Multiple Inheritance
                            1. 1. Distinguish Interface Inheritance from Implementation Inheritance
                            2. 2. Make Interfaces Explicit with ABCs
                            3. 3. Use Mixins for Code Reuse
                            4. 4. Make Mixins Explicit by Naming
                            5. 5. An ABC May Also Be a Mixin; The Reverse Is Not True
                            6. 6. Don’t Subclass from More Than One Concrete Class
                            7. 7. Provide Aggregate Classes to Users
                            8. 8. “Favor Object Composition Over Class Inheritance.”
                            9. Tkinter: The Good, the Bad, and the Ugly
                            1. Operator Overloading 101
                            2. Unary Operators
                            3. Overloading + for Vector Addition
                            4. Overloading * for Scalar Multiplication
                            5. Rich Comparison Operators
                            6. Augmented Assignment Operators
                            7. Chapter Summary
                            8. Further Reading
                            1. Sentence Take #1: A Sequence of Words
                              1. Why Sequences Are Iterable: The iter Function
                              1. Making Sentence an Iterator: Bad Idea
                              1. How a Generator Function Works
                              1. Arithmetic Progression with itertools
                              1. Do This, Then That: else Blocks Beyond if
                              2. Context Managers and with Blocks
                              3. The contextlib Utilities
                              4. Using @contextmanager
                              5. Chapter Summary
                              6. Further Reading
                              1. How Coroutines Evolved from Generators
                              2. Basic Behavior of a Generator Used as a Coroutine
                              3. Example: Coroutine to Compute a Running Average
                              4. Decorators for Coroutine Priming
                              5. Coroutine Termination and Exception Handling
                              6. Returning a Value from a Coroutine
                              7. Using yield from
                              8. The Meaning of yield from
                              9. Use Case: Coroutines for Discrete Event Simulation
                                1. About Discrete Event Simulations
                                2. The Taxi Fleet Simulation
                                1. Example: Web Downloads in Three Styles
                                  1. A Sequential Download Script
                                  2. Downloading with concurrent.futures
                                  3. Where Are the Futures?
                                  1. Error Handling in the flags2 Examples
                                  2. Using futures.as_completed
                                  3. Threading and Multiprocessing Alternatives
                                  1. Thread Versus Coroutine: A Comparison
                                    1. asyncio.Future: Nonblocking by Design
                                    2. Yielding from Futures, Tasks, and Coroutines
                                    1. Using asyncio.as_completed
                                    2. Using an Executor to Avoid Blocking the Event Loop
                                    1. Doing Multiple Requests for Each Download
                                    1. An asyncio TCP Server
                                    2. An aiohttp Web Server
                                    3. Smarter Clients for Better Concurrency
                                    1. Data Wrangling with Dynamic Attributes
                                      1. Exploring JSON-Like Data with Dynamic Attributes
                                      2. The Invalid Attribute Name Problem
                                      3. Flexible Object Creation with __new__
                                      4. Restructuring the OSCON Feed with shelve
                                      5. Linked Record Retrieval with Properties
                                      1. LineItem Take #1: Class for an Item in an Order
                                      2. LineItem Take #2: A Validating Property
                                      1. Properties Override Instance Attributes
                                      2. Property Documentation
                                      1. Special Attributes that Affect Attribute Handling
                                      2. Built-In Functions for Attribute Handling
                                      3. Special Methods for Attribute Handling
                                      1. Descriptor Example: Attribute Validation
                                        1. LineItem Take #3: A Simple Descriptor
                                        2. LineItem Take #4: Automatic Storage Attribute Names
                                        3. LineItem Take #5: A New Descriptor Type
                                        1. Overriding Descriptor
                                        2. Overriding Descriptor Without __get__
                                        3. Nonoverriding Descriptor
                                        4. Overwriting a Descriptor in the Class
                                        1. A Class Factory
                                        2. A Class Decorator for Customizing Descriptors
                                        3. What Happens When: Import Time Versus Runtime
                                          1. The Evaluation Time Exercises
                                          1. The Metaclass Evaluation Time Exercise
                                          1. Further Reading
                                          1. Chapter 3: in Operator Performance Test
                                          2. Chapter 3: Compare the Bit Patterns of Hashes
                                          3. Chapter 9: RAM Usage With and Without __slots__
                                          4. Chapter 14: isis2json.py Database Conversion Script
                                          5. Chapter 16: Taxi Fleet Discrete Event Simulation
                                          6. Chapter 17: Cryptographic Examples
                                          7. Chapter 17: flags2 HTTP Client Examples
                                          8. Chapter 19: OSCON Schedule Scripts and Tests

                                          Product information

                                          • Title: Fluent Python
                                          • Author(s): Luciano Ramalho
                                          • Release date: August 2015
                                          • Publisher(s): O’Reilly Media, Inc.
                                          • ISBN: 9781491946008

                                          Источник

Оцените статью