EventHandler, event, delegate based programming in Python any example would appreciate? [closed]
Want to improve this question? Update the questi开发者_JAVA技巧on so it can be answered with facts and citations by editing this post.
Closed last year.
Improve this questionBasically 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('joe@example.com', '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.
精彩评论