Status of side-effecting functions in python

Steven D'Aprano steve+comp.lang.python at pearwood.info
Mon Oct 27 12:30:57 CET 2014


Roy Smith wrote:

>> Yes and no. If something goes wrong in a .write() method,
>> is not Python supposed to raise an error? (!)
> 
> Define "wrong".  It is not an error for a write() call to consume fewer
> bytes than were requested.  

It's not? I'm asking a genuine question here, not a rhetorical one. I would
expect that if I ask to write 2 bytes, and only 1 byte is written, that
absolutely is an error. Under what circumstances is it okay for write() to
throw data away?

> How would you expect this to be handled in Python?  Raise
> DataPartiallyWrittenError? 

I would expect it to raise an IOError, most likely with one of the following
error codes:

* errno.EIO (physical input/output error)

* errno.EFBIG (file is too large)

* errno.ENOSPC (no space left on device, disk is full)


-- 
Steven




More information about the Python-list mailing list