Python3 write gzip file - memoryview: a bytes-like object is required, not 'str'

后端 未结 4 1220
余生分开走
余生分开走 2020-12-16 13:33

I want to write a file. Based on the name of the file this may or may not be compressed with the gzip module. Here is my code:

import gzip
filen         


        
4条回答
  •  爱一瞬间的悲伤
    2020-12-16 14:37

    you can convert it to bytes like this.

    import gzip 
    with gzip.open(filename, 'wb') as fd:
       fd.write('blah blah blah'.encode('utf-8'))
    

提交回复
热议问题