Book description
This lesson is a recipe from the Python Cookbook that explores being able to compare instances of your class using the standard comparison operators, but without having to write a lot of special methods, and avoiding the tedious task of creating implementations of every possible comparison operator.
What you'll learn—and how you can apply it
Learn how to use the functools.total_ordering decorator to simplify the comparison operator creation process.
This lesson is for you because…
You're an experienced Python programmer who wants to compare instances of your class using standard comparison operators without having to write a lot of special methods.
Prerequisites
- Moderate experience with Python
Materials or downloads needed
- None
Publisher resources
Table of contents
Product information
- Title: Making classes support comparison operations in Python
- Author(s):
- Release date: August 2016
- Publisher(s): O'Reilly Media, Inc.
- ISBN: 9781491966143
You might also like
book
Implementing stateful objects or state machines in Python
This lesson is a recipe from the Python Cookbook that explores the problem of wanting to …
book
Computational Modeling and Visualization of Physical Systems with Python
, by Jay Wang introduces computational modeling and visualization of physical systems that are commonly found …
book
Python® Create-Modify-Reuse
Python: Create-Modify-Reuse is designed for all levels of Python developers interested in a practical, hands-on way …
book
Python: Essential Reference
Python Essential Reference is the definitive reference guide to the Python programming language — the one …