Python style: exceptions vs. sys.exit()

Carl Banks pavlovevidence at
Wed Sep 24 11:12:24 CEST 2008

On Sep 23, 4:25 pm, Drake <cjdr... at> wrote:
> The
> question is: should the library function be able to just dump to
> sys.exit() with a message about the error (like "couldn't open this
> file"),

I'm kind of curious what your library is for.  Is it something where
exiting the app be the only appropriate action for an IO error?

Even if it is, I will echo other people's advice: a library should
never call exit, at least not by default.  For your imagined use it
might make sense to exit upon any failure, but other people using the
library might not want to do that.

For that matter, a library should never print error or status
messages.  Messages should either be sent to the caller somehow, or
handled using the logging facility.

Carl Banks

More information about the Python-list mailing list