wanlifeipeng

  博客园 :: 首页 :: 博问 :: 闪存 :: :: 联系 :: 订阅 订阅 :: 管理 ::

代码:

def filtered_words(path='filtered_words.txt'):
    words = []
    with open(path, 'r', encoding='utf-8', newline='')  as f:
        for line in f:
            words.append(line.strip())
    return words

def main():
    words = filtered_words()
    while True:
        #注意 python3中input相当于python2中raw_input
        text = input('content: ').strip()
     
        for word in words:
            if word in text:
                replace_str = '*' * len(word)
                text = text.replace(word,replace_str)
        print(text)

 

posted on 2017-04-08 12:24  wanlifeipeng  阅读(634)  评论(0编辑  收藏  举报