Reading and Writing Files
The
win32file module has functions for reading and
writing files. Not surprisingly,
win32file.ReadFile()
reads files, and
win32file.WriteFile()
writes files.
win32file.ReadFile() takes the following
parameters:
The file handle to read from
The size of the data to read (see the reference for further details)
Optionally, an
OVERLAPPEDorNone
win32file.ReadFile() returns two pieces of
information in a Python tuple: the error code for
ReadFile and the data itself. The error code is
either zero or the value winerror.ERROR_IO_PENDING
if overlapped I/O is being performed. All other error codes are
trapped and raises a Python exception.
win32file.WriteFile() takes the following
parameters:
A file handle opened to allow reading
The data to write
Optionally, an
OVERLAPPEDorNone
win32file.WriteFile() returns the error code from
the operation. This is either zero or
win32error.ERROR_IO_PENDING if overlapped I/O is
used. All other error codes are converted to a Python exception.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access