diff --git a/files.html b/files.html index bcad2fa..bf69ab2 100644 --- a/files.html +++ b/files.html @@ -350,20 +350,13 @@ b'\xff\xd8\xff'

File-like Objects

-

FIXME - - +

In the simplest case, a file-like object is any object with a read() method with an optional size parameter, which returns a string. When called with no size parameter, it reads everything there is to read from the input source and returns all the data as a single string. When called with a size parameter, it reads that much from the input source and returns that much data. When called again, it picks up where it left off and returns the next chunk of data. + +

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.