Skip to content

Instantly share code, notes, and snippets.

@vjayajv
Created February 3, 2022 07:51
Show Gist options
  • Save vjayajv/ee6f2ca16a786f8221b104543e954eeb to your computer and use it in GitHub Desktop.
Save vjayajv/ee6f2ca16a786f8221b104543e954eeb to your computer and use it in GitHub Desktop.
Switch Case using a JSON map in python
def foo(bla):
print(str(bla)+" from foo method")
# your statements
def bar(bla):
print(str(bla)+" from bar method")
# your statements
action_map = {
"dofoo": foo,
"dobar": bar
}
action_one = "dofoo"
action_two = "dobar"
# let's call foo
action_map[action_one]("some bla")
# let's call bar
action_map[action_two]("some bla")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment