Skip to content

Instantly share code, notes, and snippets.

@The-Quill
Last active September 23, 2016 03:20
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
A basic command prompt style thing for Python
def ls(params):
# do whatever
return True
commands = {
'ls': ls,
# ... whatever here
}
while True:
content = raw_input().split(' ')
command = content[0]
params = content[1:]
print('you ran the "{name}" command'.format(name=command))
if command == 'quit':
break;
if command in commands:
commands[command](params)
else:
print('the command "{name}" doesn\'t exist'.format(name=command))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment