> > You can access the exception object which gives you greater detail. > > > > try: > > os.unlink(some_file) > > except OSError, e: > > print e.errno > > print e.strerror > > > > if e.errno == 2: > > pass > > else: > > raise > > I do this myself in a lot of places, almost exactly like this. It's > slightly clearer to use 'if e.errno == errno.ENOENT' in my opinion, > but, whatever.
In some cases it's also more correct. While ENOENT is always 2, some error codes differ between windows and posix. In general it's better to use the constants from the errno module. Ryan -- Ryan Kelly http://www.rfk.id.au | This message is digitally signed. Please visit r...@rfk.id.au | http://www.rfk.id.au/ramblings/gpg/ for details
signature.asc
Description: This is a digitally signed message part
-- http://mail.python.org/mailman/listinfo/python-list