Antoine Pitrou <pit...@free.fr> added the comment: Hm, first, which version of the documentation are you looking at? For the new IO lib, you should probably refer to the current py3k docs: http://docs.python.org/py3k/library/io.html
Then, the documentation looks confused indeed. But your interpretation is a bit confused as well ;) RawIOBase is only an abstract base class, it doesn't provide any meaningful implementation. The doc for write() here is wrong when it says "... return the number of bytes written (This is never less than len(b), since if the write fails, an IOError will be raised)". FileIO, which is an implementation of RawIOBase (see below), *can* return less than len(b). FileIO (not RawFileIO, which doesn't exist) is an implementation of RawIOBase. Its write() method does only one system call and does not try to consume all of the input. Therefore, it can return less than the length of the input string, particularly if the underlying file is in non-blocking mode. It will return None if in non-blocking mode and *no* byte of input has been consumed (this is to distinguish from the case where the input would have been a 0-byte string). It will raise an IOError in all other error cases. However ------- In daily life, most uses of FileIO will be wrapped in a BufferedWriter, BufferedReader or BufferedRandom object (this is what happens if you use the builtin open()). These classes *will* retry when write() is called, until everything is written out or an error occurs. The only exception is if the underlying file is in non-blocking mode, in which case write() might raise a BlockingIOError if it couldn't write everything without blocking. Bottom line: write() on a *buffered* IO object (not a *raw* one) will either write everything, or raise an exception. ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue6929> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com