pythonのクラス継承&関数リロード

2256 ワード

classの継承、wait関数の再ロード.呼び出し時にインスタンス自体を呼び出す関数
class Launcher(object):
    def __init__(self, conf, restart_method='reload'):
        self.conf = conf
        self.restart_method = restart_method

    def wait(self):
        print ('Launcher')

class ServiceLauncher(Launcher):
    """Runs one or more service in a parent process."""
    def __init__(self, conf, restart_method='reload'):
        super(ServiceLauncher, self).__init__(
            conf, restart_method=restart_method)

    def wait(self):
        print ('ServiceLauncher')

launcher = ServiceLauncher('test', restart_method='reload')
launcher.wait()
 
C:\Users\Seadee\AppData\Local\Programs\Python\Python35\python.exe D:/python/project_test/my_class.py

ServiceLauncher

Process finished with exit code 0