Events: The Python Way

Antti Rasinen ars at
Sun Jul 29 07:37:03 CEST 2007

On 2007-07-29, at 02:34, David Wilson wrote:

> Hi there,
> Python has no built-in way of doing this. You may consider writing
> your own class if you like this pattern (I personally do):
> class Event(object):
>     def __init__(self):
>         self.subscribers = set()


>     def __isub__(self, subscriber):
>         self.subscribers.pop(subscriber)
>         return self

A slight typo there. For sets s.pop() returns an arbitrary element  
and s.remove(x) or s.discard(x) removes the element x from the set s.  
For the OP: remove raises an exception if x is not in the set,  
discard does not.

[ ars at <*> Antti Rasinen ]

"The music of rebellion makes you wanna rage
But it's made by millionaires who are nearly twice your age"

More information about the Python-list mailing list