Created
December 7, 2014 05:00
-
-
Save datamafia/f74ea05dd687aefd5da8 to your computer and use it in GitHub Desktop.
Dynamically call method using a variable
This file contains hidden or 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 CallMe: # Class | |
| def __init__(self): | |
| return | |
| def App(self): # Method one | |
| print 'App' | |
| def Foo(self): # Method two | |
| print 'Foo' | |
| variable = "App" # Method to call | |
| c = CallMe() | |
| getattr(c, variable)() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment