title: How to compress a text file?
body: <p>I have a text file created and I want to compress it.</p>
  
  <p>How would I accomplish this?</p>
  
  <p>I have done some research, around the forum ; found a question, similar to this but when I tried it out, it did not work as it was text typed in,  not a file, for example</p>
  
  <pre><code>import zlib, base64
  text = 'STACK OVERFLOW'
  code =  base64.b64encode(zlib.compress(text,9))
  print code
  </code></pre>
  
  <p>source from: (<a href="https://stackoverflow.com/questions/37185708/compressing-a-file-in-python-and-keep-the-grammar-exact-when-opening-it-again">Compressing a file in python and keep the grammar exact when opening it again</a>)</p>
  
  <p>When i tried it out this error came up, for example:</p>
  
  <pre><code>hTraceback (most recent call last):
  File "C:\Users\Shahid\Desktop\Suhail\Task 3.py", line 3, in &lt;module&gt;
  code =  base64.b64encode(zlib.compress(text,9))
  TypeError: must be string or read-only buffer, not file
  </code></pre>
  
  <p>Here is the code that I have used:</p>
  
  <pre><code>import zlib, base64
  text = open('Suitable.txt','r')
  code =  base64.b64encode(zlib.compress(text,9))
  print code
  </code></pre>
  
  <p>But what i want is a text file to be compressed.</p>