def filter_words(path): if os.path.isfile(path): with open(path, 'r') as f: words = f.read() words = words.replace(',', '') words = words.replace('\n', '') return words
def sense_words(): words = filter_words('filter.txt') print("敏感字内容如下:") print("------------------------------------------------------------------") print(words) print("------------------------------------------------------------------") while True: sentence = input("请输入:") if sentence == '0': print('exit') break for i in words: if i in sentence: replace = '' for j in range(len(i)): replace = replace + '*'