Created
July 23, 2019 11:06
-
-
Save Vincent-CIRCL/d075bd9b6602c573320521025851035c to your computer and use it in GitHub Desktop.
Create a class that can launch method of other classes programmatically.
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
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