You can almost do this by catching IOError and os.error, except that
the exception does not include the name of the offending file. But,
of course, this might be fixed (although it's tedious work since
millions of places in the source have to be updated, and there isn't
always an obvious filename associated with an error).
Regarding the suppression of stack traces: how about a "production
code" flag (say -p) instead of a "debugging mode" flag? I think the
default behaviour should continue to give as much help in debugging as
possible -- after all not all errors are easily reproduced, yet a
glance at the stack trace will often give the author of the code an
idea of what went wrong. Also I suspect that most python invocations
are for scripts still being debugged :-)
The -p could be placed after the interpreter name on the #! line at
the beginning of the script. (Most kernels support one word of flags
here.) To run the script with debugging enabled, simply call the
interpreter explicitly with the script file as first argument.
--Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>