From f887a6180ac374ab91d614584e26c0e30406f571 Mon Sep 17 00:00:00 2001 From: Andrew Kuchling Date: Tue, 14 Apr 2015 11:44:40 -0400 Subject: [PATCH] #21146: give a more efficient recipe in gzip docs --- Doc/library/gzip.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Doc/library/gzip.rst b/Doc/library/gzip.rst index a8e77049d37..04c41d585c8 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::