Skip to content

Instantly share code, notes, and snippets.

@Kos
Created January 3, 2013 11:02
Show Gist options
  • Save Kos/4442668 to your computer and use it in GitHub Desktop.
Save Kos/4442668 to your computer and use it in GitHub Desktop.
How to make your coworkers angry: Decorators. (Who likes nested functions?)
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