python将文本分每两行一组
程序员文章站
2022-06-05 14:26:54
# -*- 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("源文件路径","目标文件路径")
上一篇: 因为我懒
下一篇: 六一关注儿童健康 孩子吃五食物性早熟