您的位置:首页 > 编程语言 > Python开发

#初学python第一课-简单的文本过滤器#

2016-12-30 12:01 351 查看
第一个简单的python文本过滤器。

#敏感词过滤器
def text_creat(name,msg):
desktop_path = 'C:/Users/lenovo/Desktop/';
full_path = desktop_path + name + '.txt';
file = open(full_path,'w');
file.write(msg);
file.close();
print('Done');

def text_filter(word, censored_word='lame', changed_word='Awesome'):
return word.replace(censored_word, changed_word);

def wenben_filter(name,msg):
clean_msg=text_filter(msg);
text_creat(name,clean_msg);

wenben_filter('hello','python is lame lame !!!');
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: