Is the Python documentation accurate that os.pread/pwrite are only supported on Unix, not Windows? I ask what seems like a blindingly obvious question because Windows has supported these features (by different names) for nearly 20 years prior to the functions being added to Python, and 5 years prior to Unix (POSIX, specifically) supporting them.
Yes, the documentation is correct. You can see the source in posixmodule.c, or just try it out yourself.
The reason for this is that the os module works in terms of POSIX-style file descriptors, as returned by open. Windows does support POSIX-style file descriptors, but does not support the full POSIX API with them.
The Windows-specific HANDLE-based API does have a lot of similar functionality—in some cases more, in some cases less, in some cases just different. And for high-level wrappers like io for text files, asyncio for reactor loops, shutil for filesystem operations, multiprocessing for pipes, etc., Python often does use the Win32 API instead of using the incomplete POSIX API on Windows.
But for the low-level functionality in os, which mostly maps each function directly to a native function call, that kind of wrapper would be very difficult to do, especially without forcing everyone to use a very weak lowest common denominator.
This is the same reason Python doesn't support anything but Windows in os.startfile—even though macOS has had similar functionality for even longer than Windows, and Linux has had it for many years now via xdg, neither has anything exactly like what Windows has.
(Of course, as Basile Starynkevitch implies in a comment, there are cases where it would be possible to mirror an API perfectly, and it just hasn't happened because nobody's written the code for it. That was the case for os.replace on Windows up to Python 3.3, for example.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With