What's the use of the else in try/except/else?

Scott David Daniels Scott.Daniels at Acm.Org
Wed May 13 13:53:26 EDT 2009

greg wrote:
> kj wrote:
>> Wow.  As rationales for syntax constructs go, this has got to be
>> the most subtle one I've ever seen...
> It's to avoid masking bugs. Suppose you accidentally
> wrote
>   try:
>     v = mumble.field
>     sys.warming('field was actually there?')
>   except AttributeError:
>     pass
> Then you could easily fail to notice that
> you had written 'warming' instead of 'warning'.
Well, if you look, you'll discover that warning is not in the
sys module at all, but in the logging module.
So the original example already demonstrated the problem.

--Scott David Daniels
Scott.Daniels at Acm.Org

More information about the Python-list mailing list