Skip to content

Instantly share code, notes, and snippets.

@philchristensen
Created November 8, 2010 16:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save philchristensen/667924 to your computer and use it in GitHub Desktop.
Save philchristensen/667924 to your computer and use it in GitHub Desktop.
sketch idea for implementing case/switch with Python decorators
case_dict = {}
def case(key=None):
def case_builder(func):
case_dict[key] = func
return func
return case_builder
def switch(value):
return case_dict[value]
def example_switch(value):
@case('something')
def something_func():
print 'this is something'
@case('something else')
def something_func():
print 'this is something else'
switch(value)()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment