This lesson is a recipe from the Python Cookbook that explores the problem of wanting to implement a state machine or an object that operates in a number of different states, without littering your code with a lot of conditionals. It teaches key solutions such as encoding each operational state as a separate class and arranging for one class to delegate to another class, or directly manipulating certain attributes of instances.
What you'll learn—and how you can apply it
Learn how to implement a state machine or an object that operates in a number of different states, but doesn’t litter your code with a lot of conditionals. You'll also learn how to encode each operational state as a separate class and arrange for one class to delegate to the other class. Finally, see how to directly manipulate the class attribute of instances.
This lesson is for you because…
You're an experienced Python programmers who is looking to deepen your understanding of the language and modern programming idioms, such as the advanced techniques used by libraries, frameworks, and applications.
- Moderate experience as a Python programmer
Materials or downloads needed
- Title: Implementing stateful objects or state machines in Python
- Release date: August 2016
- Publisher(s): O'Reilly Media, Inc.
- ISBN: 9781491966150
You might also like
Learning Python, 5th Edition
Get a comprehensive, in-depth introduction to the core Python language with this hands-on book. Based on …
Python Crash Course, 2nd Edition
This is the second edition of the best selling Python book in the world. Python Crash …
Fluent Python, 2nd Edition
Python’s simplicity lets you become productive quickly, but often this means you aren’t using everything it …
Kubernetes in Action
Kubernetes in Action teaches you to use Kubernetes to deploy container-based distributed applications. You'll start with …