On Fri, Jan 24, 2014 at 8:38 PM, Steven D'Aprano <st...@pearwood.info> wrote: > > However, there's more to it than this. For starters, you need to decide > on the exact behaviour. Clearly, "file not found" errors should move on > to try the next prefix in the path list. But what about permission > denied errors?
Prior to 3.3, I/O operations raise an IOError, except functions in the os module raise an OSError. Inspect the exception `errno` attribute for the error code. Named error constants are available in the errno module. 3.3 makes IOError an alias for OSError and maps several of the more common error codes to subclasses that have descriptive names. Here are some examples where 3.3 OSError returns a sublcass: >>> for code in [errno.EPERM, errno.ENOENT, ... errno.EACCES, errno.EISDIR]: ... OSError(code, os.strerror(code)) ... PermissionError(1, 'Operation not permitted') FileNotFoundError(2, 'No such file or directory') PermissionError(13, 'Permission denied') IsADirectoryError(21, 'Is a directory') _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor