Glossary¶
- binary file¶
A file object able to read and write bytes-like objects. Examples of binary files are files opened in binary mode (
'rb'
,'wb'
or'rb+'
),sys.stdin.buffer
,sys.stdout.buffer
, and instances ofio.BytesIO
andgzip.GzipFile
.See also text file for a file object able to read and write
str
objects.- bytes-like object¶
An object that supports the bufferobjects and can export a C-contiguous buffer. This includes all
bytes
,bytearray
, andarray.array
objects, as well as many commonmemoryview
objects. 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
and amemoryview
of abytearray
. Other operations require the binary data to be stored in immutable objects (“read-only bytes-like objects”); examples of these includebytes
and amemoryview
of abytes
object.- contiguous¶
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
read()
orwrite()
) 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
io
module. The canonical way to create a file object is by using theopen()
function.- file-like object¶
A synonym for file object.
- text file¶
A file object able to read and write
str
objects. 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 ('r'
or'w'
),sys.stdin
,sys.stdout
, and instances ofio.StringIO
.See also binary file for a file object able to read and write bytes-like objects.
- path-like object¶
An object representing a file system path. A path-like object is either a
str
orbytes
object representing a path, or an object implementing theos.PathLike
protocol. An object that supports theos.PathLike
protocol can be converted to astr
orbytes
file system path by calling theos.fspath()
function;os.fsdecode()
andos.fsencode()
can be used to guarantee astr
orbytes
result instead, respectively. Introduced by PEP 519.