This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author madarche
Recipients georg.brandl, madarche
Date 2008-03-18.20:29:42
SpamBayes Score 0.051342823
Marked as misclassified No
Message-id <1205872183.57.0.209526870399.issue2406@psf.upfronthosting.co.za>
In-reply-to
Content
The documentation for the gzip python module as found at
http://docs.python.org/lib/module-gzip.html could be improved by code
examples. Those examples are really lacking.

Here below are the code snippets I propose. This is inspired by
http://xahlee.org/perl-python/python_doc_gzip.html but done with respect
and with another useful (I think) example.

# Example of how to decompress a file
import gzip
file_obj = gzip.GzipFile('/home/joe/file.txt.gz', 'rb');
file_content = file_obj.read()
file_obj.close()

# Example of how to create a compressed GZIP file
import gzip
file_content = "Lots of content here"
file_obj = gzip.GzipFile('/home/joe/file.txt.gz', 'wb');
file_obj.write(file_content)
file_content.close()

# Example of how to compress an existing file
import shutil
import gzip
file_obj_in = file('/home/joe/file.txt', 'rb')
file_obj_out = gzip.GzipFile('/home/joe/file.txt.gz', 'wb');
shutil.copyfileobj(file_obj_in, file_obj_out)
file_obj_out.close()


Best regards.
History
Date User Action Args
2008-03-18 20:29:43madarchesetspambayes_score: 0.0513428 -> 0.051342823
recipients: + madarche, georg.brandl
2008-03-18 20:29:43madarchesetspambayes_score: 0.0513428 -> 0.0513428
messageid: <1205872183.57.0.209526870399.issue2406@psf.upfronthosting.co.za>
2008-03-18 20:29:42madarchelinkissue2406 messages
2008-03-18 20:29:42madarchecreate