title: How to compress a processed text file in Python?
body: <p>I have a text file which I constantly append data to. When processing is done I need to gzip the file. I tried several options like <code>shutil.make_archive</code>, <code>tarfile</code>, <code>gzip</code> but could not eventually do it. Is there no simple way to compress a file without actually writing to it?</p>
  
  <p>Let's say I have <strong>mydata.txt</strong> file and I want it to be gzipped and saved as <strong>mydata.txt.gz</strong>. </p>