How to check for EOF in Python?

前端 未结 5 2421
深忆病人
深忆病人 2021-02-15 16:54

How do I check for EOF in Python? I found a bug in my code where the last block of text after the separator isn\'t added to the return list. Or maybe there\'s a better way of ex

5条回答
  •  清酒与你
    2021-02-15 17:24

    The end-of-file condition holds as soon as the for statement terminates -- that seems the simplest way to minorly fix this code (you can extract text_block.getvalue() at the end if you want to check it's not empty before appending it).

提交回复
热议问题