Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Mastering Object-oriented Python
  • Toc
  • feedback
Mastering Object-oriented Python

Mastering Object-oriented Python

By : Steven F. Lott
4.2 (13)
close
Mastering Object-oriented Python

Mastering Object-oriented Python

4.2 (13)
By: Steven F. Lott

Overview of this book

Table of Contents (26 chapters)
close
Mastering Object-oriented Python
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Some Preliminaries
Index

Using standard library mixin classes


The standard library makes use of mixin class definitions. There are several modules that contain examples, including io, socketserver, urllib.request, contextlib, and collections.abc.

When we define our own collection based on the collections.abc abstract base classes, we're making use of mixins to assure that cross-cutting aspects of the containers are defined consistently. The top-level collections (Set, Sequence, and Mapping) are all built from multiple mixins. It's very important to look at section 8.4 of the Python Standard Library to see how the mixins contribute features, as the overall structure is built up from pieces.

Looking at just one line, the summary of Sequence, we see that it inherits from Sized, Iterable, and Container. These mixin classes lead to methods of __contains__(), __iter__(), __reversed__(), index(), and count().

Using the context manager mixin class

When we looked at context managers in Chapter 5, Using Callables and Contexts...

Unlock full access

Continue reading for free

A Packt free trial gives you instant online access to our library of over 7000 practical eBooks and videos, constantly updated with the latest in tech
bookmark search playlist download font-size

Change the font size

margin-width

Change margin width

day-mode

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Delete Bookmark

Modal Close icon
Are you sure you want to delete it?
Cancel
Yes, Delete