The essential file concept
Modern OSs rely on files and device drivers for a variety of services and features. Bytes on a disk drive are only one type of file.
Note
Since many storage devices use or include Solid State Drives (SSD) the term "disk" is technically a misnomer; we'll use the outdated term.
A network adapter is another kind of file; one in which bytes are available continuously, instead of appearing at rest. In addition to disk and network files, the Linux filesystem includes the /dev
directory, which describes all of the devices on a given computer. These devices include serial ports, references to memory, and even a device which accumulates an entropy pool to provide random bytes.
The Python file object wraps an OS file. The open()
function binds a Python file object to an OS file. In addition to a name, the function expects a mode string for access. The mode string combines two features:
Characters versus bytes: By default, a file is opened in text mode; we can make this explicit...