diff --git a/files.html b/files.html index 10fec7d..b697b9a 100644 --- a/files.html +++ b/files.html @@ -439,6 +439,19 @@ AttributeError: '_io.BufferedReader' object has no attribute 'encoding'The cat command displays the contents of a file. This file contains the string you originally wrote directly to the compressed file out.log.gz from within the Python Shell. +
+

Did you get this error? +

+>>> with gzip.open('out.log.gz', mode='wb') as z_file:
+...         z_file.write('A nine mile walk is no joke, especially in the rain.'.encode('utf-8'))
+... 
+Traceback (most recent call last):
+ File "<stdin>", line 1, in <module>
+AttributeError: 'GzipFile' object has no attribute '__exit__'
+

If so, you’re probably using Python 3.0. You should really upgrade to Python 3.1. +

Python 3.0 had a gzip module, but it did not support using a gzipped-file object as a context manager. Python 3.1 added the ability to use gzipped-file objects in a with statement. +

+

Standard Input, Output, and Error