SitePoint
Blog
Forum
Library
Login
Join Premium
Toggle sidebar
The Python Master
Toggle community discussions
Close
Content
Bookmarks
Preface
The Python Master
Preface
Errata and Suggestions
Conventions Used in This Book
Welcome!
Prerequisites
The Road Goes On Forever
1
Advanced Flow Control
else clauses on loops
An alternative to loop else clauses
The try..except..else construct
Emulating switch
Dispatching on Type
singledispatch
Summary
Byte Oriented Programming
Bitwise operators
The bytes type in depth
The mutable bytearray sequence
Interpreting byte streams with the struct module
Memory Views
Memory-mapped files
Summary
Object Internals and Custom Attributes
How are Python objects stored?
Using vars() to access __dict__
Overriding __getattribute__()
Special methods which bypass __getattribute__()
Where are the methods?
Slots
Descriptors
A review of properties
Unravelling the property function
Implementing a descriptor
Retrieving descriptors on classes
Data versus non-data descriptors
Summary
Instance Creation
Instance Creation
Customising allocation
Summary
Metaclasses
The class of class objects
Class allocation and initialisation
Passing additional arguments to the metaclass
Metaclass methods and visibility
Fine-grained instantiation control with metaclass __call__()
Practical metaclass examples
Metaclasses and Inheritance
Summary
Class decorators
A first class decorator
Enforcing constraints with a class decorator
Enforcing constraints for properties
Chaining class decorators
Summary
Abstract Base Classes
What is an abstract base-class?
Why are abstract base-classes useful?
What about duck typing?
Abstract base-classes in Python
Defining subclasses with __subclasscheck__()
Non-transitivity of subclass relationships
Library support for abstract base-classes
Combining abstractmethod with other decorators
Propagating abstractness through descriptors
Fixing our @invariant class decorator with ABCs
Summary
Afterword: Continue the journey
Notes
Open text modal
Community Questions
Close