Posted in Python onMarch 19, 2018
核心代码
# -*- coding: utf-8 -*- ''' python读取英文文件,将每个单词按照空格分开,并将每个单词独自放一行 ''' def dcfenhang(infile,outfile): infopen = open(infile,'r',encoding='utf-8') outopen = open(outfile,'w',encoding='utf-8') lines = infopen.readlines() for line in lines: for db in line.split(): if db not in outfile: outopen.write(db+'\n') infopen.close() outopen.close() dcfenhang("3water.txt","fenci.txt")
3water.txt文件
welcome to visit 3water.com
Thans very much
效果如下图所示
这篇文章就介绍到这了,希望大家以后多多支持三水点靠木。
python将每个单词按空格分开并保存到文件中
- Author -
为援不可图声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
Reply on: @reply_date@
@reply_contents@