目录太长了,文字超过系统限制,只好分成两次
Classes and OOP
Chapter 26 OOP: The Big Picture
Why Use Classes?
OOP from 30,000 Feet
Chapter Summary
Test Your Knowledge: Quiz
Test Your Knowledge: Answers
Chapter 27 Class Coding Basics
Classes Generate Multiple Instance Objects
Classes Are Customized by Inheritance
Classes Can Intercept Python Operators
The World’s Simplest Python Class
Chapter Summary
Test Your Knowledge: Quiz
Test Your Knowledge: Answers
Chapter 28 A More Realistic Example
Step 1: Making Instances
Step 2: Adding Behavior Methods
Step 3: Operator Overloading
Step 4: Customizing Behavior by Subclassing
Step 5: Customizing Constructors, Too
Step 6: Using Introspection Tools
Step 7 (Final): Storing Objects in a Database
Future Directions
Chapter Summary
Test Your Knowledge: Quiz
Test Your Knowledge: Answers
Chapter 29 Class Coding Details
The class Statement
Methods
Inheritance
Namespaces: The Conclusion
Documentation Strings Revisited
Classes Versus Modules
Chapter Summary
Test Your Knowledge: Quiz
Test Your Knowledge: Answers
Chapter 30 Operator Overloading
The Basics
Indexing and Slicing: __getitem__ and __setitem__
Index Iteration: __getitem__
Iterable Objects: __iter__ and __next__
Membership: __contains__, __iter__, and __getitem__
Attribute Access: __getattr__ and __setattr__
String Representation: __repr__ and __str__
Right-Side and In-Place Uses: __radd__ and __iadd__
Call Expressions: __call__
Comparisons: __lt__, __gt__, and Others
Boolean Tests: __bool__ and __len__
Object Destruction: __del__
Chapter Summary
Test Your Knowledge: Quiz
Test Your Knowledge: Answers
Chapter 31 Designing with Classes
Python and OOP
OOP and Inheritance: “Is-a” Relationships
OOP and Composition: “Has-a” Relationships
OOP and Delegation: “Wrapper” Proxy Objects
Pseudoprivate Class Attributes
Methods Are Objects: Bound or Unbound
Classes Are Objects: Generic Object Factories
Multiple Inheritance: “Mix-in” Classes
Other Design-Related Topics
Chapter Summary
Test Your Knowledge: Quiz
Test Your Knowledge: Answers
Chapter 32 Advanced Class Topics
Extending Built-in Types
The “New Style” Class Model
New-Style Class Changes
New-Style Class Extensions
Static and Class Methods
Decorators and Metaclasses: Part 1
The super Built-in Function: For Better or Worse?
Class Gotchas
Chapter Summary
Test Your Knowledge: Quiz
Test Your Knowledge: Answers
Test Your Knowledge: Part VI Exercises
Exceptions and Tools
Chapter 33 Exception Basics
Why Use Exceptions?
Exceptions: The Short Story
Chapter Summary
Test Your Knowledge: Quiz
Test Your Knowledge: Answers
Chapter 34 Exception Coding Details
The try/except/else Statement
The try/finally Statement
Unified try/except/finally
The raise Statement
The assert Statement
with/as Context Managers
Chapter Summary
Test Your Knowledge: Quiz
Test Your Knowledge: Answers
Chapter 35 Exception Objects
Exceptions: Back to the Future
Why Exception Hierarchies?
Built-in Exception Classes
Custom Print Displays
Custom Data and Behavior
Chapter Summary
Test Your Knowledge: Quiz
Test Your Knowledge: Answers
Chapter 36 Designing with Exceptions
Nesting Exception Handlers
Exception Idioms
Exception Design Tips and Gotchas
Core Language Summary
Chapter Summary
Test Your Knowledge: Quiz
Test Your Knowledge: Answers
Test Your Knowledge: Part VII Exercises
Advanced Topics
Chapter 37 Unicode and Byte Strings
String Changes in 3.X
String Basics
Coding Basic Strings
Coding Unicode Strings
Using 3.X bytes Objects
Using 3.X/2.6+ bytearray Objects
Using Text and Binary Files
Using Unicode Files
Other String Tool Changes in 3.X
Chapter Summary
Test Your Knowledge: Quiz
Test Your Knowledge: Answers
Chapter 38 Managed Attributes
Why Manage Attributes?
Properties
Descriptors
__getattr__ and __getattribute__
Example: Attribute Validations
Chapter Summary
Test Your Knowledge: Quiz
Chapter 39 Decorators
What’s a Decorator?
The Basics
Coding Function Decorators
Coding Class Decorators
Managing Functions and Classes Directly
Example: “Private” and “Public” Attributes
Example: Validating Function Arguments
Chapter Summary
Test Your Knowledge: Quiz
Test Your Knowledge: Answers
Chapter 40 Metaclasses
To Metaclass or Not to Metaclass
The Metaclass Model
Declaring Metaclasses
Coding Metaclasses
Inheritance and Instance
Metaclass Methods
Example: Adding Methods to Classes
Example: Applying Decorators to Methods
Chapter Summary
Test Your Knowledge: Quiz
Test Your Knowledge: Answers
Chapter 41 All Good Things
The Python Paradox
Where to Go From Here
Encore: Print Your Own Completion Certificate!
Appendixes
Appendix Installation and Configuration
Installing the Python Interpreter
Configuring Python
For More Help
Appendix The Python 3.3 Windows Launcher
The Unix Legacy
The Windows Legacy
Introducing the New Windows Launcher
A Windows Launcher Tutorial
Pitfalls of the New Windows Launcher
Conclusions: A Net Win for Windows
Appendix Python Changes and This Book
Major 2.X/3.X Differences
General Remarks: 3.X Changes
Fifth Edition Python Changes: 2.7, 3.2, 3.3
Fourth Edition Python Changes: 2.6, 3.0, 3.1
Third Edition Python Changes: 2.3, 2.4, 2.5
Earlier and Later Python Changes
Appendix Solutions to End-of-Part Exercises
Part I, Getting Started
Part II, Types and Operations
Part III, Statements and Syntax
Part IV, Functions and Generators
Part V, Modules and Packages
Part VI, Classes and OOP
Part VII, Exceptions and Tools
Colophon
|