[Python-Dev] Exception type on handling closed files
Fredrik Lundh
fredrik at pythonware.com
Mon Dec 12 08:32:47 CET 2005
João Paulo Silva wrote:
> >>> a = file("dir/foo")
> >>> a.close()
> >>> a.read()
>
> Traceback (most recent call last):
> File "<pyshell#28>", line 1, in -toplevel-
> a.read()
> ValueError: I/O operation on closed file
>
> Shoudn't this raise IOError? Seems more semantically correct to me.
IOError is, as the documentation says, used "when an I/O operation fails
for an I/O related reason", while ValueError is used "when an argument has
the right type but an inappropriate value."
</F>
More information about the Python-Dev
mailing list