From 52d695d76909f8148057ab3da2e61c220030ec10 Mon Sep 17 00:00:00 2001 From: Mark Pilgrim Date: Sun, 16 Aug 2009 13:43:53 -0400 Subject: [PATCH] mention io.BytesIO --- files.html | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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.'
    -
  1. The io module contains the definition of the StringIO class that you can use to treat a string in memory as a file. +
  2. The io module defines the StringIO class that you can use to treat a string in memory as a file.
  3. To create a stream object out of a string, create an instance of the 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.
  4. Calling the read() method “reads” the entire “file,” which in the case of a StringIO object simply returns the original string.
  5. Just like a real file, calling the read() method again returns an empty string. @@ -398,6 +398,10 @@ AttributeError: '_io.BufferedReader' object has no attribute 'encoding'You can also read the string in chunks, by passing a size parameter to the read() method.
+
+

io.StringIO lets you treat a string as a file. There’s also a io.BytesIO class, which lets you treat a byte array as a file. +

+

Handling Compressed Files

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.)