title: How to check for EOF in Python?
body: <p>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 expressing this function?</p>
  
  <p>Here's my code:</p>
  
  <pre><code>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
  </code></pre>