python将文本分每两行一组
程序员文章站
2023-09-11 11:44:51
# -*- coding: utf-8 -*-
'''
python读取文件,每两行为一组
'''
def fenhan...
# -*- coding: utf-8 -*- ''' python读取文件,每两行为一组 ''' def fenhang(infile,outfile): infopen = open(infile,'r',encoding='utf-8') outopen = open(outfile,'w',encoding='utf-8') lines = infopen.readlines() i = 1 for line in lines: if i % 2 == 0: outopen.write(line+'\n') else: outopen.write(line) i += 1 infopen.close() outopen.close() fenhang("源文件路径","目标文件路径")
下一篇: 中国特色小吃排行榜 全国十大特色小吃