forked from p46318075/CodePattern
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.
26 lines
697 B
26 lines
697 B
9 months ago
|
from cppy.cp_util import *
|
||
|
|
||
8 months ago
|
# 这种连续方法调用,看起来也比较舒服
|
||
|
# 每一个类方法返回 self ,另外最后一个方法注意是否有返回值
|
||
|
|
||
|
class Flow:
|
||
|
def extract_file_words(self, filepath):
|
||
|
self.data = extract_file_words(filepath)
|
||
|
return self
|
||
|
|
||
|
def get_frequencies(self):
|
||
|
self.data = get_frequencies(self.data)
|
||
|
return self
|
||
|
|
||
|
def sort_dict(self):
|
||
|
self.data = sort_dict(self.data)
|
||
|
return self
|
||
|
|
||
|
def print_word_freqs(self, n):
|
||
|
print_word_freqs(self.data, n)
|
||
|
return self
|
||
|
|
||
|
|
||
|
# 顺序调用
|
||
|
Flow().extract_file_words(testfilepath).get_frequencies().sort_dict().print_word_freqs(10)
|