From: Andrew Kuchling Date: Tue, 14 Apr 2015 15:44:40 +0000 (-0400) Subject: #21146: give a more efficient recipe in gzip docs X-Git-Tag: v3.5.0a4~60 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f887a6180ac374ab91d614584e26c0e30406f571;p=thirdparty%2FPython%2Fcpython.git #21146: give a more efficient recipe in gzip docs --- diff --git a/Doc/library/gzip.rst b/Doc/library/gzip.rst index a8e77049d370..04c41d585c8e 100644 --- a/Doc/library/gzip.rst +++ b/Doc/library/gzip.rst @@ -189,9 +189,10 @@ Example of how to create a compressed GZIP file:: Example of how to GZIP compress an existing file:: import gzip + import shutil with open('/home/joe/file.txt', 'rb') as f_in: with gzip.open('/home/joe/file.txt.gz', 'wb') as f_out: - f_out.writelines(f_in) + shutil.copyfileobj(f_in, f_out) Example of how to GZIP compress a binary string::