Basically I'm a C# developer, I know the way C# does, EventHandler, delegate, even...
but whats the best way to implement it on Python.
Basically I'm a C# developer, I know the way C# does, EventHandler, delegate, even...
but whats the best way to implement it on Python.
I think you should be able to use a function:
def do_work_and_notify(on_done):
// do work
on_done()
def send_email_on_completion():
email_send('[email protected]', 'you are done')
do_work_and_notify(send_email_on_completion)
Functions (and even methods) in python are first-class objects that can be tossed around like anything else in the language.
This question is a lot like Python Observer Pattern: Examples, Tips? which has lots of great answers. There's even an implementation of C#-like events in Python.