14

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.

2 Answers 2

21

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.

Sign up to request clarification or add additional context in comments.

1 Comment

How to go about if let's say on_done function takes some number of arguments?
2

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.