python .txt文件奇数偶数行分开保存
2022/2/20 21:00:41
本文主要是介绍python .txt文件奇数偶数行分开保存,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
def fenhang(infile,outfile,outfile1): infopen = open(infile,'r',encoding='utf-8') outopen = open(outfile,'w',encoding='utf-8') outopen1 = open(outfile1, 'w', encoding='utf-8') lines = infopen.readlines() i = 0 for line in lines: i += 1 if i % 2 == 0: outopen.write(line) else: outopen1.write(line) infopen.close() outopen.close() if __name__=="__main__": infile='/Wnt/Wnt_proteinB.txt' outfile='/Wnt/Wnt_proteinBBBB.txt' ####偶数行 outfile1='/Wnt_proteinnameB.txt' ####奇数行 fenhang(infile,outfile,outfile1)
这篇关于python .txt文件奇数偶数行分开保存的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-16`PyMuPDF4LLM`:提取PDF数据的神器
- 2024-11-16四种数据科学Web界面框架快速对比:Rio、Reflex、Streamlit和Plotly Dash
- 2024-11-14获取参数学习:Python编程入门教程
- 2024-11-14Python编程基础入门
- 2024-11-14Python编程入门指南
- 2024-11-13Python基础教程
- 2024-11-12Python编程基础指南
- 2024-11-12Python基础编程教程
- 2024-11-08Python编程基础与实践示例
- 2024-11-07Python编程基础指南