title: python generator of generators?
body: <p>I wrote a class that reads a txt file. The file is composed of blocks of non-empty lines (let's call them "sections"), separated by an empty line:</p>
  
  <pre><code>line1.1
  line1.2
  line1.3
  
  line2.1
  line2.2
  </code></pre>
  
  <p>My first implementation was to read the whole file and return a list of lists, that is a list of sections, where each section is a list of lines.
  This was obviously terrible memory-wise.</p>
  
  <p>So I re-implemented it as a generator of lists, that is at every cycle my class reads a whole section in memory as a list and yields it.</p>
  
  <p>This is better, but it's still problematic in case of large sections. So I wonder if I can reimplement it as a generator of generators? The problem is that this class is very generic, and it should be able to satisfy both of these use cases:</p>
  
  <ol>
  <li>read a very big file, containing very big sections, and cycle through it only once. A generator of generators is perfect for this.</li>
  <li><p>read a smallish file into memory to be cycled over multiple times. A generator of lists works fine, because the user can just invoke</p>
  
  <p>list(MyClass(file_handle))</p></li>
  </ol>
  
  <p>However, a generator of generators would NOT work in case 2, as the inner objects would not be transformed to lists.</p>
  
  <p>Is there anything more elegant than implementing an explicit to_list() method, that would transform the generator of generators into a list of lists?</p>