1. jhjaggars
  2. dictionary_switches

Source

dictionary_switches / code / TableDriven / command_registration.py

command_table = {}

def command(name):
    def _add_to_command_table(function):
        command_table[name] = function
        return function
    return _add_to_command_table

@command('demo')
def demo_command():
    print("this is the demo command...")

if __name__ == "__main__":
    try:
        command_table['demo']()
        command_table['not_here']()
    except KeyError as e:
        print("could not find demo command: ", e)