Created
January 19, 2014 19:39
-
-
Save svschannak/8509962 to your computer and use it in GitHub Desktop.
Call a method of a class by its name.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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