Librería Portfolio Librería Portfolio

Búsqueda avanzada

TIENE EN SU CESTA DE LA COMPRA

0 productos

en total 0,00 €

FLUENT PYTHON. CLEAR, CONCISE, AND EFFECTIVE PROGRAMMING
Título:
FLUENT PYTHON. CLEAR, CONCISE, AND EFFECTIVE PROGRAMMING
Subtítulo:
Autor:
RAMALHO, L
Editorial:
O´REILLY
Año de edición:
2015
Materia
UNIX
ISBN:
978-1-4919-4600-8
Páginas:
770
43,95 €

 

Sinopsis

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.

This book covers:

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



Prologue
Chapter 1The Python Data Model
A Pythonic Card Deck
How Special Methods Are Used
Overview of Special Methods
Why len Is Not a Method
Chapter Summary
Further Reading
Data Structures
Chapter 1An Array of Sequences
Overview of Built-In Sequences
List Comprehensions and Generator Expressions
Tuples Are Not Just Immutable Lists
Slicing
Using + and * with Sequences
Augmented Assignment with Sequences
list.sort and the sorted Built-In Function
Managing Ordered Sequences with bisect
When a List Is Not the Answer
Chapter Summary
Further Reading
Chapter 2Dictionaries and Sets
Generic Mapping Types
dict Comprehensions
Overview of Common Mapping Methods
Mappings with Flexible Key Lookup
Variations of dict
Subclassing UserDict
Immutable Mappings
Set Theory
dict and set Under the Hood
Chapter Summary
Further Reading
Chapter 3Text versus Bytes
Character Issues
Byte Essentials
Basic Encoders/Decoders
Understanding Encode/Decode Problems
Handling Text Files
Normalizing Unicode for Saner Comparisons
Sorting Unicode Text
The Unicode Database
Dual-Mode str and bytes APIs
Chapter Summary
Further Reading
Functions as Objects
Chapter 1First-Class Functions
Treating a Function Like an Object
Higher-Order Functions
Anonymous Functions
The Seven Flavors of Callable Objects
User-Defined Callable Types
Function Introspection
From Positional to Keyword-Only Parameters
Retrieving Information About Parameters
Function Annotations
Packages for Functional Programming
Chapter Summary
Further Reading
Chapter 2Design Patterns with First-Class Functions
Case Study: Refactoring Strategy
Command
Chapter Summary
Further Reading
Chapter 3Function Decorators and Closures
Decorators 101
When Python Executes Decorators
Decorator-Enhanced Strategy Pattern
Variable Scope Rules
Closures
The nonlocal Declaration
Implementing a Simple Decorator
Decorators in the Standard Library
Stacked Decorators
Parameterized Decorators
Chapter Summary
Further Reading
Object-Oriented Idioms
Chapter 1Object References, Mutability, and Recycling
Variables Are Not Boxes
Identity, Equality, and Aliases
Copies Are Shallow by Default
Function Parameters as References
del and Garbage Collection
Weak References
Tricks Python Plays with Immutables
Chapter Summary
Further Reading
Chapter 2A Pythonic Object
Object Representations
Vector Class Redux
An Alternative Constructor
classmethod Versus staticmethod
Formatted Displays
A Hashable Vector2d
Private and "Protectedö Attributes in Python
Saving Space with the __slots__ Class Attribute
Overriding Class Attributes
Chapter Summary
Further Reading
Chapter 3Sequence Hacking, Hashing, and Slicing
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 4Interfaces: From Protocols to ABCs
Interfaces and Protocols in Python Culture
Python Digs Sequences
Monkey-Patching to Implement a Protocol at Runtime
Alex Martelli's Waterfowl
Subclassing an ABC
ABCs in the Standard Library
Defining and Using an ABC
How the Tombola Subclasses Were Tested
Usage of register in Practice
Geese Can Behave as Ducks
Chapter Summary
Further Reading
Chapter 5Inheritance: For Good or For Worse
Subclassing Built-In Types Is Tricky
Multiple Inheritance and Method Resolution Order
Multiple Inheritance in the Real World
Coping with Multiple Inheritance
A Modern Example: Mixins in Django Generic Views
Chapter Summary
Further Reading
Chapter 6Operator Overloading: Doing It Right
Operator Overloading 101
Unary Operators
Overloading + for Vector Addition
Overloading * for Scalar Multiplication
Rich Comparison Operators
Augmented Assignment Operators
Chapter Summary
Further Reading
Control Flow
Chapter 1Iterables, Iterators, and Generators
Sentence Take #1: A Sequence of Words
Iterables Versus Iterators
Sentence Take #2: A Classic Interior
Sentence Take #3: A Generator Function
Sentence Take #4: A Lazy Implementation
Sentence Take #5: A Generator Expression
Generator Expressions: When to Use Them
Another Example: Arithmetic Progression Generator
Generator Functions in the Standard Library
New Syntax in Python 3.3: yield from
Iterable Reducing Functions
A Closer Look at the iter Function
Case Study: Generators in a Database Conversion Utility
Generators as Coroutines
Chapter Summary
Further Reading
Chapter 2Context Managers and else Blocks
Do This, Then That: else Blocks Beyond if
Context Managers and with Blocks
The contextlib Utilities
Using @contextmanager
Chapter Summary
Further Reading
Chapter 3Coroutines
How Coroutines Evolved from Generators
Basic Behavior of a Generator Used as a Coroutine
Example: Coroutine to Compute a Running Average
Decorators for Coroutine Priming
Coroutine Termination and Exception Handling
Returning a Value from a Coroutine
Using yield from
The Meaning of yield from
Use Case: Coroutines for Discrete Event Simulation
Chapter Summary
Further Reading
Chapter 4Concurrency with Futures
Example: Web Downloads in Three Styles
Blocking I/O and the GIL
Launching Processes with concurrent.futures
Experimenting with Executor.map
Downloads with Progress Display and Error Handling
Chapter Summary
Further Reading
Chapter 5Concurrency with asyncio
Thread Versus Corout