Created
January 3, 2013 11:02
-
-
Save Kos/4442668 to your computer and use it in GitHub Desktop.
How to make your coworkers angry: Decorators. (Who likes nested functions?)
This file contains 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
import operator | |
commands = {} | |
@operator.attrgetter('__get__') | |
def command(name, func): | |
commands[name] = func | |
return func | |
@command('Hello') | |
def hello_command(x): | |
print 'hello,',x | |
commands['Hello']('gist') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment