Readable run-time state machine
Project description
Enables a finite state machine to be created at run-time AND leverage simple attribute syntax creating self documenting code.
Normally these concepts are mutually exclusive, and in any finished design can hard coded. This module is handy during prototyping.
Usage
>>> from rrsm import StateMachine
>>> #Instantiation works with a list of the form ['state', ...]
... #or a dictionary of the form {'state' : value, ...}
... SM = StateMachine(['cool', 'off', 'on', 'warm'])
>>> #checking state works against strings or integers:
... SM == 'cool'
True
>>> #Change the state
... SM('warm')
>>> #using attributes to check state:
... SM == SM.cool
False
>>> SM == SM.warm
True
>>> SM.current_state
'warm'
>>> SM.current_code
3
For hardcoded finite state machines, the Super State Machine project seems like a more promising solution.
This implementation has no dependencies, nor does it import any of the standard library. It should work on any python version, but it’s tested with 2.6, 2.7, 3.3 and 2.4. Some exceptions probably apply to the exception handling. Pun intended.
Install
The easiest way to install is:
pip install rrsm
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file rrsm-0.2.0.zip
.
File metadata
- Download URL: rrsm-0.2.0.zip
- Upload date:
- Size: 6.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 805b59d543caeab6cc58f97143469a12790cca7d88fd3180ccd72c067703e330 |
|
MD5 | 6176ae5a882e9f24d22e27783d2fb47e |
|
BLAKE2b-256 | 4b287f441ece7fb54571594f6cc90c7b22e46c4114c959815471a2fdcc2c7891 |