-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy path1.7.py
More file actions
26 lines (22 loc) · 759 Bytes
/
1.7.py
File metadata and controls
26 lines (22 loc) · 759 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#coding: utf-8
import cmd
# 存放敏感词文件的路径
filtered_words_filepath = 'd:/filtered_words.txt'
class CLI(cmd.Cmd):
def __init__(self): #初始基础类方法
cmd.Cmd.__init__(self) # 初始化,提取敏感词列表
self.intro = 'Python敏感词检测:' #输出欢迎信息
f = open(filtered_words_filepath)
self.words = list(map(lambda i: i.strip('\n'), f.readlines()))
self.prompt = ">>> " # 定义提示符
def default(self, line):
if any([i in line for i in self.words]):
print ('Freedom')
else:
print ('Human Rights')
def do_quit(self, arg):
exit()
return True
if __name__ =="__main__":
cli = CLI()
cli.cmdloop()