Commit 38a4f7a3 authored by Antoine Pitrou's avatar Antoine Pitrou

Merged revisions 84156 via svnmerge from

svn+ssh://pythondev@svn.python.org/python/branches/py3k

........
  r84156 | antoine.pitrou | 2010-08-17 23:11:49 +0200 (mar., 17 août 2010) | 3 lines

  Modernize gzip examples
........
parent f72006f4
...@@ -88,26 +88,22 @@ Examples of usage ...@@ -88,26 +88,22 @@ Examples of usage
Example of how to read a compressed file:: Example of how to read a compressed file::
import gzip import gzip
f = gzip.open('/home/joe/file.txt.gz', 'rb') with gzip.open('/home/joe/file.txt.gz', 'rb') as f:
file_content = f.read() file_content = f.read()
f.close()
Example of how to create a compressed GZIP file:: Example of how to create a compressed GZIP file::
import gzip import gzip
content = "Lots of content here" content = b"Lots of content here"
f = gzip.open('/home/joe/file.txt.gz', 'wb') with gzip.open('/home/joe/file.txt.gz', 'wb') as f:
f.write(content) f.write(content)
f.close()
Example of how to GZIP compress an existing file:: Example of how to GZIP compress an existing file::
import gzip import gzip
f_in = open('/home/joe/file.txt', 'rb') with open('/home/joe/file.txt', 'rb') as f_in:
f_out = gzip.open('/home/joe/file.txt.gz', 'wb') with f_out = gzip.open('/home/joe/file.txt.gz', 'wb') as f_out:
f_out.writelines(f_in) f_out.writelines(f_in)
f_out.close()
f_in.close()
.. seealso:: .. seealso::
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment