- binary file¶
A file object able to read and write bytes-like objects. Examples of binary files are files opened in binary mode (
sys.stdout.buffer, and instances of
See also text file for a file object able to read and write
- bytes-like object¶
An object that supports the bufferobjects and can export a C-contiguous buffer. This includes all
array.arrayobjects, as well as many common
memoryviewobjects. Bytes-like objects can be used for various operations that work with binary data; these include compression, saving to a binary file, and sending over a socket.
Some operations need the binary data to be mutable. The documentation often refers to these as “read-write bytes-like objects”. Example mutable buffer objects include
bytearray. Other operations require the binary data to be stored in immutable objects (“read-only bytes-like objects”); examples of these include
A buffer is considered contiguous exactly if it is either C-contiguous or Fortran contiguous. Zero-dimensional buffers are C and Fortran contiguous. In one-dimensional arrays, the items must be laid out in memory next to each other, in order of increasing indexes starting from zero. In multidimensional C-contiguous arrays, the last index varies the fastest when visiting items in order of memory address. However, in Fortran contiguous arrays, the first index varies the fastest.
- file object¶
An object exposing a file-oriented API (with methods such as
write()) to an underlying resource. Depending on the way it was created, a file object can mediate access to a real on-disk file or to another type of storage or communication device (for example standard input/output, in-memory buffers, sockets, pipes, etc.). File objects are also called file-like objects or streams.
There are actually three categories of file objects: raw binary files, buffered binary files and text files. Their interfaces are defined in the
iomodule. The canonical way to create a file object is by using the
- file-like object¶
A synonym for file object.
- text file¶
A file object able to read and write
strobjects. Often, a text file actually accesses a byte-oriented datastream and handles the text encoding automatically. Examples of text files are files opened in text mode (
sys.stdout, and instances of
- path-like object¶
An object representing a file system path. A path-like object is either a
bytesobject representing a path, or an object implementing the
os.PathLikeprotocol. An object that supports the
os.PathLikeprotocol can be converted to a
bytesfile system path by calling the
os.fsencode()can be used to guarantee a
bytesresult instead, respectively. Introduced by PEP 519.