私は次のようなことを提案します:
# if python 2.x
#from itertools import tee, izip
# if python 3
from itertols import tee
# http://docs.python.org/2/library/itertools.html#recipes
def pairwise(iterable):
"s -> (s0,s1), (s1,s2), (s2, s3), ..."
a, b = tee(iterable)
next(b, None)
# if python 2.x
#return izip(a, b)
return zip(a, b)
new_data = []
with open('temp100.txt', 'r') as sqFile:
for sLine, edit_line in pairwise(seqFile):
# I think this is just new_line = tempLine
#tempLine = edit_line[:20]
#new_line = editLine.replace(editLine, tempLine)
new_data.append(sLine + editLine[:20])
if len(sLine) > 20:
new_data.append('\n')
with open("new_temp100.txt", "w") as new:
new.write(''.join(new_data))
ディスクに直接ストリーミングするだけで、おそらくもっとうまくいくでしょう
# if python 2.x
#from itertools import tee, izip
# if python 3
from itertols import tee
# http://docs.python.org/2/library/itertools.html#recipes
def pairwise(iterable):
"s -> (s0,s1), (s1,s2), (s2, s3), ..."
a, b = tee(iterable)
next(b, None)
# if python 2.x
#return izip(a, b)
return zip(a, b)
new_data = []
with open('temp100.txt', 'r') as sqFile:
with open("new_temp100.txt", "w") as new:
for sLine, edit_line in pairwise(seqFile):
tmp_str = sLine + editLine[:20]
if len(sLine) > 20:
tmp_str = tmp_str + '/n'
new.write(tmp_str)
そのため、ファイルの内容全体をメモリに保持する必要はありません