Tim Chase <python.l...@tim.thechases.com>: > Interesting. I read up on os.open() and os.read() > https://docs.python.org/2/library/os.html#os.read > but didn't notice anything there clarifying that it was unbuffered > compared to the __builtins__.open() and fp.read() functions. > > Could you point me to resources where I can learn more about the > distinctions?
It is not explained very clearly in the documentation, but the os.* functions are thin wrappers around the analogous C functions (system calls or standard library functions). There is just this allusion: Note that using the file descriptor directly will bypass the file object methods, ignoring aspects such as internal buffering of data. <URL: https://docs.python.org/3/library/os.html?#file-descriptor-op erations> The os.* facilities are ultimately documented in the Linux man pages. File object buffering can be turned off by adding buffering=0 to the high-level open() builtin function: When no buffering argument is given, the default buffering policy works as follows: * Binary files are buffered in fixed-size chunks; the size of the buffer is chosen using a heuristic trying to determine the underlying device’s “block size” and falling back on io.DEFAULT_BUFFER_SIZE. On many systems, the buffer will typically be 4096 or 8192 bytes long. <URL: https://docs.python.org/3/library/functions.html#open> In general, system programming is best done using system programming facilities, ie, os.*. Marko -- https://mail.python.org/mailman/listinfo/python-list