You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
978 B

9 months ago
from cppy.cp_util import *
class Calculator:
def frequencies(self,word_list):
return get_frequencies(word_list)
def sort(self,word_freq):
return sort_dict( word_freq)
def print_all(self,word_freqs):
print_word_freqs(word_freqs[1:])
##########################################
# 应用框架
##########################################
def call_method(obj, method_name, *args):
# 使用内省的 getattr 函数动态获取 obj 对象的 method_name 方法
method = getattr(obj, method_name, None)
if method:
return method(*args) # 动态调用方法
else:
return "Method not found."
if __name__ == '__main__':
# 流水线处理方法清单
method_names = ' frequencies sort print_all'
data = extract_file_words( testfilepath )
calc = Calculator()
for method_name in method_names.split():
data = call_method( calc,method_name,data )