PythonでEOFを確認するにはどうすればよいですか? 区切り記号の後のテキストの最後のブロックが返されるリストに追加されないバグがコードに見つかりました。それとも、この関数を表現するより良い方法がありますか?
これが私のコードです:
def get_text_blocks(filename):
text_blocks = []
text_block = StringIO.StringIO()
with open(filename, 'r') as f:
for line in f:
text_block.write(line)
print line
if line.startswith('-- -'):
text_blocks.append(text_block.getvalue())
text_block.close()
text_block = StringIO.StringIO()
return text_blocks