Reading utf-8 characters from a gzip file in python

后端 未结 5 1127
执念已碎
执念已碎 2020-12-14 07:38

I am trying to read a gunzipped file (.gz) in python and am having some trouble.

I used the gzip module to read it but the file is encoded as a utf-8 text file so ev

5条回答
  •  独厮守ぢ
    2020-12-14 07:57

    Maybe

    import codecs
    zf = gzip.open(fname, 'rb')
    reader = codecs.getreader("utf-8")
    contents = reader( zf )
    for line in contents:
        pass
    

提交回复
热议问题