Skip to content

Instantly share code, notes, and snippets.

@datamafia
Created December 7, 2014 05:00
Show Gist options
  • Select an option

  • Save datamafia/f74ea05dd687aefd5da8 to your computer and use it in GitHub Desktop.

Select an option

Save datamafia/f74ea05dd687aefd5da8 to your computer and use it in GitHub Desktop.
Dynamically call method using a variable
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