Skip to content

Instantly share code, notes, and snippets.

@svschannak
Created January 19, 2014 19:39
Show Gist options
  • Save svschannak/8509962 to your computer and use it in GitHub Desktop.
Save svschannak/8509962 to your computer and use it in GitHub Desktop.
Call a method of a class by its name.
class Result():
def __init__(self, type):
self.type = type
def FirstDefinition(self):
pass
def SecondDefinition(self):
pass
def __repr__(self):
method = getattr(self, "%sDefinition" % self.type)
return method()
#example use: Result(type='First')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment