diff --git a/files.html b/files.html index 2703d8a..1382c91 100644 --- a/files.html +++ b/files.html @@ -390,7 +390,7 @@ AttributeError: '_io.BufferedReader' object has no attribute 'encoding' >>> a_file.read() 'new black.'
io module contains the definition of the StringIO class that you can use to treat a string in memory as a file.
+io module defines the StringIO class that you can use to treat a string in memory as a file.
io.StringIO() class and pass it the string you want to use as your “file” data. Now you have a stream object, and you can do all sorts of stream-like things with it.
read() method “reads” the entire “file,” which in the case of a StringIO object simply returns the original string.
read() method again returns an empty string.
@@ -398,6 +398,10 @@ AttributeError: '_io.BufferedReader' object has no attribute 'encoding'
read() method.
++☞
io.StringIOlets you treat a string as a file. There’s also aio.BytesIOclass, which lets you treat a byte array as a file. +
The Python standard library contains modules that support reading and writing compressed files. There are a number of different compression schemes; the two most popular on non-Windows systems are gzip and bzip2. (You may have also encountered PKZIP archives and GNU Tar archives. Python has modules for those, too.)