Skip to content

Instantly share code, notes, and snippets.

@animationdavid
Created March 20, 2021 10:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save animationdavid/fa5050f69457e7c93ad86125cb14d953 to your computer and use it in GitHub Desktop.
Save animationdavid/fa5050f69457e7c93ad86125cb14d953 to your computer and use it in GitHub Desktop.
Python Switcher
class Switcher(object):
def numbers_of_options(self, argument):
"""Dispatch method"""
method_name = 'option_' + str(argument)
method = getattr(self, method_name, lambda: "Invalid option")
return method()
def option_1(self):
return "My option 1"
def option_2(self):
return "My option 2"
def option_3(self):
return "My option 3"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment