File Objects

File objects can be used not only to access normal disk files, but also any other type of “file” that uses that abstraction. Once the proper “hooks” are installed, you can access other objects with file-like interfaces in the same manner you would access normal files.
 
The open() built-in function (see below) returns a file object which is then used for all succeeding operations on the file in question. There are a large number of other functions which return a file or file-like object. One primary reason for this abstraction is that many input/output data structures prefer to adhere to a common interface. It provides consistency in behavior as well as implementation. Operating systems like Unix even feature files as an underlying and architectural interface for communication. Remember, files are simply a contiguous sequence of bytes. Anywhere data needs to be sent usually involves a byte stream of some sort, whether the stream occurs as individual bytes or blocks of data.