Quote:
Originally Posted by Darkhack
|
BURN!!!! Hahahaha.
I'm sure that wasn't actually your question. You should probably specify what you mean by that. Are you talking about case-sensitive circumstances, or situations where there may be other garbage tagged along with it?
Or are you talking about how you could elegantly link each command to a different function call, without repetitive code?
I'd look into the idea of using a dictionary to map each command to a function call:
def output (*args):
print args[0][0]
def list_of_files (*args):
pass
def run_file (*args):
pass
# parse the input in to a command and list of parameters
command = 'put'
params = ['"Text Here"']
# turn the command into a function pointer
commands = {"put":output, "dir":list_of_files, "start":run_file}
function = commands[command]
# call the function pointer with the parsed parameters
function (params)