[Python-Dev] POSIX [Fuzziness in io module specs]

Greg Ewing greg.ewing at canterbury.ac.nz
Sun Sep 20 02:23:20 CEST 2009


Nick Coghlan wrote:

> For example, a file not existing, a file being locked by another
> process, and the user not having write permissions to the file are
> problems that demand very different responses from the user.

You can display an error-specific message without having
to inspect the error code, e.g.

   try:
     something_with_file(path)
   except EnvironmentError, e:
     report_error("Couldn't do that with %s: %s" % (path, e))

This is a pattern I use a lot, and it seems to work
pretty well.

-- 
Greg


More information about the Python-Dev mailing list