浏览文章
文章信息
Python自动加载模块
13311
代码:
class Manager(): server = None def __init__(self, server: str): """ 初始化...提供商 :param server: """ self.server = server def get(self): """ 获取代理 :return: """ server = self.__getattr__() return server.get_proxy_auth_plugin_path() def __getattr__(self): """ 自动加载服务模块 :rtype: ServersInterface """ module = __import__('Proxy.Servers.' + self.server, None, None, ('Proxy.Servers')) return getattr(module, self.server)() # # if (__name__ == '__main__'): # manager = Manager('Abuyun') # print(manager.get())