洞察纵观鸿蒙next版本,如何凭借FinClip加强小程序的跨平台管理,确保企业在数字化转型中的高效运营和数据安全?
660
2022-11-03
使用python实现\记事本中去除掉空行数据
代码如下:
"""读取存在空行的文件,删除其中的空行,并将其保存到新的文件中"""def rewrite(): with open('src-test.txt','r',encoding = 'utf-8') as fr,open('newsrc-test.txt','w',encoding = 'utf-8') as fd: for text in fr.readlines(): if text.split(): fd.write(text) print('输出成功....') with open('src-train.txt','r',encoding = 'utf-8') as fr,open('newsrc-train.txt','w',encoding = 'utf-8') as fd: for text in fr.readlines(): if text.split(): fd.write(text) print('输出成功....') with open('src-val.txt','r',encoding = 'utf-8') as fr,open('newsrc-val.txt','w',encoding = 'utf-8') as fd: for text in fr.readlines(): if text.split(): fd.write(text) print('输出成功....')
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~