如何检查Python中的EOF?我在代码中发现了一个错误,其中分隔符后的最后一个文本块没有添加到返回列表中。或者,也许有更好的方式来表达这个功能?如何检查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
现在尝试,固定我的功能X2 =( – 2010-01-03 04:37:18