[issue2406] Improvement suggestions for the gzip module documentation

M.-A. DARCHE report at bugs.python.org
Tue Mar 18 21:29:43 CET 2008


New submission from M.-A. DARCHE <madarche at users.sourceforge.net>:

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.

----------
assignee: georg.brandl
components: Documentation
messages: 63981
nosy: georg.brandl, madarche
severity: normal
status: open
title: Improvement suggestions for the gzip module documentation

__________________________________
Tracker <report at bugs.python.org>
<http://bugs.python.org/issue2406>
__________________________________


More information about the Python-bugs-list mailing list