[Python-Dev] Exception Reorg PEP checked in
Guido van Rossum
gvanrossum at gmail.com
Sun Aug 14 21:27:18 CEST 2005
On 8/14/05, Michael Hudson <mwh at python.net> wrote:
> Wilfredo Sánchez Vega <wsanchez at wsanchez.net> writes:
> > I'm curious about why Python lacks FileNotFoundError,
> > PermissionError and the like as subclasses of IOError.
> Good question. Lack of effort/inertia?
Well, I wonder how often it's needed. My typical use is this:
f = open(filename)
except IOError, err:
print "Can't open %s: %s" % (filename, err)
and the error printed contains all the necessary details (in fact it
even repeats the filename, so I could probably just say "print err").
Why do you need to know the exact reason for the failure? If you
simply want to know whether the file exists, I'd use os.path.exists()
or isfile(). (Never mind that this is the sometimes-frowned-upon
look-before-you-leap; I think it's often fine.)
Also note that providing the right detail can be very OS specific.
Python doesn't just run on Unix and Windows.
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-Dev