Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 985
shahjapan Avatar asked Feb 02 '10 13:02

shahjapan


People also ask

Is an EventHandler a delegate?

The EventHandler delegate is a predefined delegate that specifically represents an event handler method for an event that does not generate data. If your event does generate data, you must use the generic EventHandler<TEventArgs> delegate class.

How are delegates used in event handling?

A delegate is a type that holds a reference to a method. A delegate is declared with a signature that shows the return type and parameters for the methods it references, and it can hold references only to methods that match its signature. A delegate is thus equivalent to a type-safe function pointer or a callback.


1 Answers

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.

like image 192
Emil Ivanov Avatar answered Oct 23 '22 21:10

Emil Ivanov