Skip to content

Instantly share code, notes, and snippets.

@takwas
Created January 12, 2016 18:46
Show Gist options
  • Save takwas/801617c69af45702adea to your computer and use it in GitHub Desktop.
Save takwas/801617c69af45702adea to your computer and use it in GitHub Desktop.
Python 'list' vs 'class' comparison
"""
List of actions:
do_help
do_about
"""
# standard library imports
import re
# local imports
import utils
def do_help(msg=None):
if msg is None:
return \
"""
Showing general help.
List of commands:
:help, :about, :inbox, :link, :log, :masters, :paste, :whatdidimiss, :resource, :submit
For help on a command, type:
:help [command]
E.g :help paste
"""
elif utils.is_valid_cmd(msg):
return 'Showing help for command: <:{cmd}>'.format(cmd=msg)
else:
return "No help for {cmd}. Type ':help' for list of commands.".format(cmd=msg)
def do_about(msg):
pass
# local imports
import actions
cmds = {
'help' : Command(cmd='help', action=actions.do_help,
help=
"""
Usage:\t:help [<command>]
"""
),
'about' : (actions.do_about, "some help text", ),
}
class Command(object):
def __init__(self, cmd, action, help_text):
self.cmd = cmd
self.action = action
self.help_text = help_text
def get_help(self):
return self.help_text
def get_action(self):
return self.action
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment