title: Reading utf-8 characters from a gzip file in python
body: <p>I am trying to read a gunzipped file (.gz) in python and am having some trouble.</p>
  
  <p>I used the gzip module to read it but the file is encoded as a utf-8 text file so eventually it reads an invalid character and crashes. </p>
  
  <p>Does anyone know how to read gzip files encoded as utf-8 files? I know that there's a codecs module that can help but I can't understand how to use it.</p>
  
  <p>Thanks!</p>
  
  <pre><code>import string
  import gzip
  import codecs
  
  f = gzip.open('file.gz','r')
  
  engines = {}
  line = f.readline()
  while line:
      parsed = string.split(line, u'\u0001')
  
      #do some things...
  
      line = f.readline()
  for en in engines:
    print(en)
  </code></pre>