title: Python Gzip - Appending to file on the fly
body: <p>Is it possible to append to a gzipped text file on the fly using Python ?</p>
  
  <p>Basically I am doing this:-</p>
  
  <pre><code>import gzip
  content = "Lots of content here"
  f = gzip.open('file.txt.gz', 'a', 9)
  f.write(content)
  f.close()
  </code></pre>
  
  <p>A line is appended (note "appended") to the file every 6 seconds or so, but the resulting file is just as big as a standard uncompressed file (roughly 1MB when done).</p>
  
  <p>Explicitly specifying the compression level does not seem to make a difference either.</p>
  
  <p>If I gzip an existing uncompressed file afterwards, it's size comes down to roughly 80kb.</p>
  
  <p>Im guessing its not possible to "append" to a gzip file on the fly and have it compress ?</p>
  
  <p>Is this a case of writing to a String.IO buffer and then flushing to a gzip file when done ?</p>