jtushman / state_machine

Python State Machine for humans
MIT License
400 stars 31 forks source link

NameError: name 'acts_as_state_machine' is not defined #28

Open snakelab opened 6 years ago

snakelab commented 6 years ago

Hi,

first thanks for sharing your code!

I get an error at running the example code:

Traceback (most recent call last): File "./state_state_machine.py", line 7, in <module> @acts_as_state_machine NameError: name 'acts_as_state_machine' is not defined

Any idea what is the problem?

thanks

snakelab commented 6 years ago

Got it: I have to add:

from state_machine import *

ghost commented 5 years ago

I have the same problem but adding 'from state_machine import ' didn't help me ` from state_machine import @acts_as_state_machine class Process: created = State(initial=True) running = State() terminated = State()

run = Event(from_states=created, to_state=running)
terminate = Event(from_states=running, to_state=terminated)
def __init__(self, name):
    self.name = name

@after('run') def run_info(self): print(f'{self.name} is running')

@before('terminate') def terminate_info(self): print(f'{self.name} terminated')

if name == 'main':

p = Process('Test')
p.current_state
p.run()
p.terminate()`