Events in Python?

Avizoa at gmail.com Avizoa at gmail.com
Wed Apr 26 12:08:29 EDT 2006


redefined.horizons at gmail.com wrote:
> Here is another non-pythonic question from the Java Developer. (I beg
> for forgiveness...)
>
> Does Python have a mechanism for events/event-driven programming?
>
> I'm not necessarily talking about just GUIs either, I'm interested in
> using events for other parts of an application as well.
>
> If there isn't some sort of event mechanism built into Python, where
> might I find some information about implementing one?
>
> Thanks,
>
> Scott Huey


Technically this is a question more of perception than capability.

All programming languages are event driven.

Calling a function is an event, for instance.

What I suspect you mean is an event management system, which is what OO
state machines are all about.

If you actually mean something akin in function to GUI event systems,
you're really talking about message passing. In the case of message
passing you just need to build a simple event manager class that echoes
a message to all subscribed listening objects. In python that message
can be a function, object, arguments, text, etc. This is easily done
without threading, in case you're worried about that. The function of
the event manager that is used for the purpose of initiating events can
simply call a particular method of all subscribing objects held in a
list.

Simple as can be :)

~Brendan Kohler




More information about the Python-list mailing list