From 7e21f9ce71983cc8cc4db404292745e7dbfe6473 Mon Sep 17 00:00:00 2001 From: Mark Pilgrim Date: Sat, 18 Jul 2009 22:49:01 -0400 Subject: [PATCH] more on #file-like-objects --- files.html | 50 +++++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/files.html b/files.html index bf69ab2..f4e2ff5 100644 --- a/files.html +++ b/files.html @@ -358,32 +358,32 @@ b'\xff\xd8\xff'

You know, like a real file object. The difference is that you’re not limiting yourself to real files. The input source that’s being “read” could be anything: a web page, a string in memory, even the output of another program. As long as your functions take a file-like object and simply call the object’s read() method, you can handle any input source that acts like a file, without specific code to handle each kind of input. - +

  • FIXME +
  • FIXME Now you have a file-like object, and you can do all sorts of file-like things with it. +
  • Calling the read() method “reads” the entire “file,” which in the case of a StringIO object simply returns the original string. +
  • Just like a real file, calling the read() method again returns an empty string. +
  • You can explicitly seek to the beginning of the string, just like seeking through a real file, by using the seek() method of the StringIO object. +
  • You can also read the string in chunks, by passing a size parameter to the read() method. +

    Standard Input, Output, and Error