As discussed earlier in this
file is a built-in type in Python. With a
file object, you can read and/or write data to a file as seen by the
underlying operating system. Python reacts to any I/O error related
to a file object by raising an instance of built-in exception class
IOError. Errors that cause this exception include
open failing to open or create a file, calling a
method on a file object to which that method doesn’t
apply (e.g., calling
write on a read-only file
object or calling
seek on a non-seekable file),
and I/O errors diagnosed by a file object’s methods.
This section documents file objects, as well as some auxiliary
modules that help you access and deal with their
You normally create a Python file object
with the built-in
open, which has the following
the file named by
filename, which must be
a string that denotes any path to a file.
returns a Python file object, which is an instance of the built-in
file is just
first introduced in Python 2.2. If you explicitly pass a
filename if the file does not
already exist (depending on the value of
mode, as we’ll discuss in
a moment). In other words, despite its name,
is not limited to opening existing files, but is also able to create
new ones if needed.
is a string that denotes how the file ...