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文件奇数偶数行分开保存
Python脚本:文件按行拆分并分别写入奇偶文件
最新推荐文章于 2023-05-05 12:37:39 发布
这段代码展示了如何使用Python将一个文本文件的行按奇偶数行分开,将偶数行写入一个文件,奇数行写入另一个文件,适用于数据预处理或简单的文本操作。
部署运行你感兴趣的模型镜像
您可能感兴趣的与本文相关的镜像
Python3.8
Conda
Python
Python 是一种高级、解释型、通用的编程语言,以其简洁易读的语法而闻名,适用于广泛的应用,包括Web开发、数据分析、人工智能和自动化脚本
8万+

被折叠的 条评论
为什么被折叠?



