Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am jeroenpelgrims on github.
  • I am jeroenpelgrims (https://keybase.io/jeroenpelgrims) on keybase.
  • I have a public key whose fingerprint is 2B08 0181 5480 1ACD 220D 5D88 DAD2 25EA 08C4 2380

To claim this, I am signing this object:

@jeroenpelgrims
jeroenpelgrims / python events.py
Created August 27, 2010 19:58
In relation to this blog post: http://blog.jeroenpelgrims.be/2010/08/using-c-style-events-in-python/ and the question posed in the comments. Would like some help improving the code.
class Event(object):
def __init__(self):
self.__handlers = []
def subscribe(self, handler):
self.__handlers.append(handler)
def unsubscribe(self, handler):
self.__handlers.remove(handler)
from mkdict import mkdict
d = mkdict({
'key1' : 'value1', #regular dictionary usage
('key2', 'key3') : 'value2' #these tuple keys will be unpacked to regular keys
})
print d['key1'] #value1
print d['key2'] #value2
print d['key3'] #value2