def get_plugin_by_name(self, package, clazz_name): """ package 类所在路径 clazz_name 类名 http://stackoverflow.com/questions/547829/how-to-dynamically-load-a-python-class https://docs.python.org/2/library/functions.html?highlight=__import__#__import__ :param package: :param clazz_name: :return: """ try: plugin_name = clazz_name.capitalize() + ‘Plugin‘ module = __import__(package + ‘.‘ + clazz_name, fromlist=[plugin_name]) claz = getattr(module, plugin_name) return claz(region_id=self.get_current_region_id(), access_key=self.aliyun_access_key) except Exception as exp: LOG.error("Get plugin: %s by package: %s error for %s" % (clazz_name, package, exp,))
本文出自 “技术人生” 博客,请务必保留此出处http://wangyuelucky.blog.51cto.com/1011508/1751969
原文:http://wangyuelucky.blog.51cto.com/1011508/1751969