Skip to content

Instantly share code, notes, and snippets.

@sdqali
Created June 19, 2012 17:54
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 sdqali/2955562 to your computer and use it in GitHub Desktop.
Save sdqali/2955562 to your computer and use it in GitHub Desktop.
options = {
'init': init_journal,
'safekeep': safekeep,
'jot': jot
}
options.get(command, wrong_command)()
@nibrahim
Copy link

You could just have have three functions called init, safekeep and jot and then simply say locals()[command]() to get your action handler. If your handlers were methods, it would be even nicer and you can call getattr(object, command)().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment