Created
August 14, 2015 21:53
-
-
Save komly/de55de3b92dc28a313b5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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