Python Forum

Full Version: [solved] compressing files with python.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi everyone,

I'm looking for Pytonic readable way to compress files.

I've found https://docs.python.org/3/library/gzip.html

with which I came out with

import gzip with open('/somewhere/aFile.whatever', 'rb') as ToBeCompressed: ReadedBytes = ToBeCompressed.read() with gzip.open('/somewhere/destination.gz', 'wb') as f: f.write(ReadedBytes )
so it work, but within the gz , the file lost it's filename is became 'destination/destination'

Any ideas how to keep or set the filename ?

Or any other method to compress and save ?

Thanks.
Never mind I found an easy way -->

https://docs.python.org/3/library/tarfile.html