
On Fri, 22 Oct 2004, John Goerzen wrote:
In Python, a file handle is just another object. It has certain methods that Python programmers expect to find: read(), readlines(), write(), writelines(), seek(), tell(), etc. This is useful because even things do not correspond to OS-level file descriptors can be accessed as files. In Python, this is used so that a file-like interface is available for gzip/gunzip interfaces, strings, SSL connections, bzip2, files from FTP, etc. That means that almost any function designed to work with an on-disk file could also work transparently read from a gzipped file, a string, etc.
If all of these objects can be represented as Strings or at least as Lists in many cases you only need a function that reads or writes the complete disk object, such as readFile and writeFile. You can apply all string or list functions respectively on the contents of the file and lazy evaluation assures a streaming behaviour of the complete process. Though I'm afraid, seeking won't work this way.