Created
January 21, 2016 10:42
-
-
Save takwas/ee6cb514d86ef3c1af4a to your computer and use it in GitHub Desktop.
Which of these snippets uses a better approach?
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
################### | |
# FILE: commands.py | |
################### | |
cmds = { | |
'help' : Command(cmd='help', callback=actions.do_help, | |
help_text= \ | |
""" | |
Usage: | |
U1:\t:help | |
Show general help. | |
U2:\t:help <command> | |
Show help for <command>. Use <U1> for a | |
list of valid commands. | |
""" | |
), | |
'about' : Command(cmd='about', callback=actions.do_about, | |
help_text= \ | |
""" | |
Usage: | |
U1:\t:about | |
Show 'about' information for this bot. | |
""" | |
), | |
submit' : Command(cmd='submit', callback=actions.do_submit, | |
help_text= \ | |
""" | |
Usage: | |
U1:\t:submit | |
Show help for this command. | |
U2:\t:submit <some_text> | |
Send a feedback to this bot's developer. <some_text> is the message to send. | |
""" | |
) | |
} | |
################ | |
# FILE: utils.py | |
################ | |
def is_valid_cmd(cmd): | |
from commands import cmds | |
return cmds.has_key(cmd) |
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
################### | |
# FILE: commands.py | |
################### | |
cmds = { | |
'help' : Command(cmd='help', callback=actions.do_help, | |
help_text= \ | |
""" | |
Usage: | |
U1:\t:help | |
Show general help. | |
U2:\t:help <command> | |
Show help for <command>. Use <U1> for a | |
list of valid commands. | |
""" | |
), | |
'about' : Command(cmd='about', callback=actions.do_about, | |
help_text= \ | |
""" | |
Usage: | |
U1:\t:about | |
Show 'about' information for this bot. | |
""" | |
), | |
submit' : Command(cmd='submit', callback=actions.do_submit, | |
help_text= \ | |
""" | |
Usage: | |
U1:\t:submit | |
Show help for this command. | |
U2:\t:submit <some_text> | |
Send a feedback to this bot's developer. <some_text> is the message to send. | |
""" | |
) | |
} | |
def get_command(cmd): | |
return cmds.get(cmd,None) | |
################ | |
# FILE: utils.py | |
################ | |
def is_valid_cmd(cmd): | |
import commands | |
return commands.get_command(cmd) is not None |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment