Skip to content

Instantly share code, notes, and snippets.

@Vincent-CIRCL
Created July 23, 2019 11:06
Show Gist options
  • Save Vincent-CIRCL/d075bd9b6602c573320521025851035c to your computer and use it in GitHub Desktop.
Save Vincent-CIRCL/d075bd9b6602c573320521025851035c to your computer and use it in GitHub Desktop.
Create a class that can launch method of other classes programmatically.
print("test")
class Test():
def __init__(self) :
print("initiated")
def start(self):
print("started")
def stop(self):
print("stopped")
class launcher():
def __init__(self):
self.myclass = None
self.startmethod = None
self.stopmethod = None
def start(self):
func = getattr(self.myclass,self.startmethod,None)
func()
def stop(self):
func = getattr(self.myclass,self.stopmethod,None)
func()
test_obj = Test()
lncher = launcher()
lncher.myclass = test_obj
lncher.startmethod= "start"
lncher.stopmethod = "stop"
lncher.start()
lncher.stop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment