Skip to content

Instantly share code, notes, and snippets.

@komly
Created August 14, 2015 21:53
Show Gist options
  • Save komly/de55de3b92dc28a313b5 to your computer and use it in GitHub Desktop.
Save komly/de55de3b92dc28a313b5 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
all_commands = {} # dict: name => func
def command(func):
all_commands[func.__name__] = func
return func
@command
def hello(name):
return "Hello, %s" % name
@command
def sum_numbers(a, b):
return str(int(a) + int(b))
class Server:
def run(self):
while True:
command, *args = input().split()
try:
print(all_commands[command](*args))
except KeyError:
command_list = '\n'.join(all_commands.keys())
print("Unknown command, avaible commands:\n" + command_list)
Server().run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment