gzip a file in Python

后端 未结 7 2051
悲&欢浪女
悲&欢浪女 2020-12-28 12:47

I want to gzip a file in Python. I am trying to use the subprocss.check_call(), but it keeps failing with the error \'OSError: [Errno 2] No such file or directory\'. Is ther

7条回答
  •  有刺的猬
    2020-12-28 12:52

    import gzip
    
    def gzip_file(src_path, dst_path):
        with open(src_path, 'rb') as src, gzip.open(dst_path, 'wb') as dst:
            for chunk in iter(lambda: src.read(4096), b""):
                dst.write(chunk)
    

提交回复
热议问题