核心代码

# -*- 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("jb51.txt","fenci.txt")

jb51.txt文件

welcome to visit jb51.net
Thans very much

效果如下图所示

python将每个单词按空格分开并保存到文件中

这篇文章就介绍到这了,希望大家以后多多支持。

华山资源网 Design By www.eoogi.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
华山资源网 Design By www.eoogi.com