on_exit pass parameters #590
Replies: 1 comment
-
A copy/paste of my SO answer. Does this answer your question?: The section of
For your particular example this could look like this: from transitions import Machine
class Matter(object):
def say_hello(self, param):
print(f"hello, new state! Here is your param: {param}")
# Every callback MUST be able to process possible callback parameters
# If parameters are not needed, just use *args and **kwargs in the definition
def say_goodbye(self, *args):
print("goodbye, old state!")
lump = Matter()
machine = Machine(lump, states=[{'name': 'solid', 'on_exit': 'say_goodbye'},
'liquid',
{'name': 'gas', 'on_enter': 'say_hello'}],
transitions=[['sublimate', 'solid', 'gas']], initial='solid')
# pass param as arg
lump.sublimate(lump.state)
# or as kwarg
# lump.sublimate(param=lump.state) There is also a second way to pass data by passing
This might be more suitable for your use case since an from transitions import Machine, EventData
class Matter(object):
def say_hello(self, event: EventData):
print(f"hello, new state! Here is your param: {event.kwargs['param']}. "
f"I came here from state '{event.transition.source}'.")
def say_goodbye(self, event):
print("goodbye, old state!")
lump = Matter()
machine = Machine(lump, states=[{'name': 'solid', 'on_exit': 'say_goodbye'},
'liquid',
{'name': 'gas', 'on_enter': 'say_hello'}],
transitions=[['sublimate', 'solid', 'gas']], initial='solid', send_event=True)
lump.sublimate(param=42) |
Beta Was this translation helpful? Give feedback.
-
Howdy,
I was wondering if on the on_exit you can pass parameters. If you have any thoughts please let me know.
class Model(object):
def Send_Email(self, emails: list):
print(emails)
print("Emailing Notify")
Working:
"on_exit":[
"Create_Form"
]
Goal:
"on_exit":[
"Create_Form(["xy@xy.com","ad@ad.com"])"
]
Beta Was this translation helpful? Give feedback.
All reactions