Created
May 9, 2011 22:43
-
-
Save EntityReborn/963577 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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