Professional Python
Реклама. ООО «ЛитРес», ИНН: 7719571260.
Оглавление
Luke Sneeringer. Professional Python
Introduction
Who This Book Is For
What This Book Covers
How This Book Is Structured
What You Need to Use This Book
Conventions
Errata
p2p.wrox.com
Part I. Functions
Chapter 1. Decorators
Understanding Decorators
Decorator Syntax
Where Decorators Are Used
Why You Should Write Decorators
When You Should Write Decorators
Writing Decorators
Decorating Classes
Type Switching
Summary
Chapter 2. Context Managers
What Is a Context Manager?
Context Manager Syntax
When You Should Write Context Managers
A Simpler Syntax
Summary
Chapter 3. Generators
Understanding What a Generator Is
Understanding Generator Syntax
Communication with Generators
Iterables Versus Iterators
Generators in the Standard Library
When to Write Generators
When Are Generators Singletons?
Generators within Generators
Summary
Part II. Classes
Chapter 4. Magic Methods
Magic Method Syntax
Available Methods
Other Magic Methods
Summary
Chapter 5. Metaclasses
Classes and Objects
Writing Metaclasses
Using Metaclasses
When to Use Metaclasses
The Question of Explicit Opt-In
Meta-Coding
Summary
Chapter 6. Class Factories
A Review of type
Understanding a Class Factory Function
Determining When You Should Write Class Factories
Summary
Chapter 7. Abstract Base Classes
Using Abstract Base Classes
Declaring a Virtual Subclass
Declaring a Protocol
Built-in Abstract Base Classes
Summary
Part III. Data
Chapter 8. Strings and Unicode
Text String Versus Byte String
Strings with Non-ASCII Characters
Other Encodings
Reading Files
Reading Other Sources
Specifying Python File Encodings
Strict Codecs
Summary
Chapter 9. Regular Expressions
Why Use Regular Expressions?
Regular Expressions in Python
Basic Regular Expressions
Grouping
Lookahead
Flags
Substitution
Compiled Regular Expressions
Summary
Part IV. Everything Else
Chapter 10. Python 2 Versus Python 3
Cross-Compatibility Strategies
Changes in Python 3
Standard Library Relocations
Version Detection
Summary
Chapter 11. Unit Testing
The Testing Continuum
Testing Code
Unit Testing Frameworks
Mocking
Other Testing Tools
Summary
Chapter 12. CLI Tools
OPTPARSE
ARGPARSE
Summary
Chapter 13. asyncio
The Event Loop
Coroutines
Futures and Tasks
Callbacks
Task Aggregation
Queues
Servers
Summary
Chapter 14. Style
Principles
Standards
Summary
About the Author
About the Technical Editors
Credits
Acknowledgments
WILEY END USER LICENSE AGREEMENT
Отрывок из книги
This book introduces the reader to more advanced Python programming by providing an intermediate course in the Python language.
Recently, Python has become more and more frequently the developer's language of choice. It is used all over the world, for myriad purposes. As adoption continues to increase, more and more developers are spending their days writing Python.
.....
Running the error function in the Python interpreter gives you the following:
Note that only the JSONOutputError exception class (and any subclasses) receives this special handling. Any other exception is passed through normally, and generates a traceback. Consider this function:
.....