「python入門」readlines()でファイルを読み込み、2行毎に処理を行うサンプル

pythonコード
# -*- coding: utf-8 -*-
def writeFileFunc(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()

Comments are closed.