@andymitchhank/

dict-based-switch

Python

No description

fork
loading
Files
  • main.py
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
def action_run():
  print('running')


def action_walk():
  print('walking')


def action_skip():
  print('skipping')


def default():
  print('defaulting')


actions = {
  'run': action_run,
  'walk': action_walk,
  'skip': action_skip,
}


def get(action_name):
  return actions.get(action_name, default)


def run(action_name, *args, **kwargs):
  return get(action_name)(*args, **kwargs)


if __name__ == '__main__':
  run('run')