Python gzip folder structure when zipping single file

前端 未结 4 1608

I\'m using Python\'s gzip module to gzip content for a single file, using code similar to the example in the docs:

import gzip
content = \"Lots of content he         


        
4条回答
  •  时光说笑
    2021-01-13 17:35

    It looks like you will have to use GzipFile directly:

    import gzip
    content = "Lots of content here"
    real_f = open('/home/joe/file.txt.gz', 'wb')
    f = gzip.GZipFile('file.txt.gz', fileobj=real_f)
    f.write(content)
    f.close()
    real_f.close()
    

    It looks like open doesn't allow you to specify the fileobj separate from the filename.

提交回复
热议问题