Argparse, and linking to methods in Subclasses

Michele Simionato michele.simionato at gmail.com
Mon Jul 18 13:56:45 CEST 2011


Here is an example by using my own library plac (http://pypi.python.org/pypi/plac):

class Server():
    def configure_logging(self, logging_file):
        pass
    def check(self):
        pass
    def deploy(self):
        pass
    def configure(self):
        pass
    def __init__(self, hostname):
        self.hostname = hostname

class SpamServer(Server):
    def check(self):
        pass

class HamServer(Server):
    def deploy(self):
        pass


def main(classname, hostname, methname): # add error checking at will
    instance = globals()[classname](hostname)
    getattr(instance, methname)()

if __name__ == '__main__':
    import plac; plac.call(main)



More information about the Python-list mailing list