Skip to content

Instantly share code, notes, and snippets.

@mw3i
Created July 20, 2019 16:28
Show Gist options
  • Save mw3i/151b3fb95f01a0e7fcf8f686702905f5 to your computer and use it in GitHub Desktop.
Save mw3i/151b3fb95f01a0e7fcf8f686702905f5 to your computer and use it in GitHub Desktop.
A simple shell in python
## Python Commander
class simple_shell():
def __init__(self):
while True:
self.listener()
## Listener Function (required)
def listener(self):
self.user_input = input('---\nuser: ').split(' ')
try:
getattr(self, self.user_input[0])()
except Exception as e:
print(e)
## Commands are Python Functions you edit
def test(self):
print('this was a test command')
def exit(self):
print('exiting...')
exit()
if __name__ == '__main__':
print('\n\n\nhey.')
c = simple_shell()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment