开发者

EventHandler, event, delegate based programming in Python any example would appreciate? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.

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 question

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('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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜