Skip to content

Instantly share code, notes, and snippets.

@EntityReborn
Created May 9, 2011 22:43
Show Gist options
  • Save EntityReborn/963577 to your computer and use it in GitHub Desktop.
Save EntityReborn/963577 to your computer and use it in GitHub Desktop.
from collections import defaultdict
class Manager(object):
def __init__(self):
self.strings = defaultdict(list) # { stringname: [func1, func2, ...], ... }
def deco(self, string):
def decofunc(func):
self.strings[string].append(func)
return func
return decofunc
m = Manager()
@m.deco("somestring")
def myfunc(var1, var2, var3):
print var1, var2, var3
myfunc(1, 2, 3) # 1 2 3
print m.strings # defaultdict(<type 'list'>, {'somestring': [<function myfunc at 0x00B695B0>]})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment