You can save the commands in a dictionary with a tuple and do something similar to store the commands.
command = {} command['skype'] = 'C:\Program Files (x86)\Skype\Phone', 'Skype.exe' command['explorer'] = 'C:\Windows\', 'Explorer.exe'
You can then do the following to execute the correct command based on user input.
if raw_input.lower().strip() in command: # Check to see if input is defined in the dictionary. os.chdir(command[raw_input][0]) # Gets Tuple item 0 (eg C:\Program Files.....) os.startfile(command[myIraw_inputput][1]) # Gets Tuple item 1 (eg Skype.exe)
More information on Dictionaries and Tuples here .
If you need to allow multiple commands, you can split them into spaces and split commands into an array.
for input in raw_input.split(): if input.lower().strip() in command: # Check to see if input is defined in the dictionary. os.chdir(command[input][0]) # Gets Tuple item 0 (eg C:\Program Files.....) os.startfile(command[input][4]) # Gets Tuple item 1 (eg Skype.exe)
This will allow you to issue commands like skype explorer , but keep in mind that there is no room for typos, so they should be an exact match, separated only by white spaces. As an example, you can write explorer , but not explorer! .
source share