import configparser, importlib.machinery from cppy.cp_util import * class PluginManager: def __init__(self): self.plugins = {} def load_plugins(self): _dir = os.path.dirname(os.path.abspath(__file__)) os.chdir(_dir) config = configparser.ConfigParser() config.read("config.ini") frequencies_plugin = config.get("Plugins", "frequencies") # 加载插件 self.plugins['word_freqs'] = importlib.machinery.SourcelessFileLoader('', frequencies_plugin).load_module() def get_plugin(self, name): return self.plugins.get(name) # 创建 PluginManager 实例 plugin_manager = PluginManager() plugin_manager.load_plugins() wordlist = extract_file_words(testfilepath) # 提取文件中的单词 word_freqs = plugin_manager.get_plugin('word_freqs').top_word(wordlist) # 调用实例方法 print_word_freqs(word_freqs) # 打印词频