Python's Exception, and Capitalization

Ray ray_usenet at yahoo.com
Fri Aug 12 10:28:10 EDT 2005


Hello guys,

OK, I've been reading some more about Python. There are some things
about Python exception that I haven't been able to grasp:

1. This is a small thing, but why is object spelled "object", and the
mother of all exception "Exception" (with capital E)? Why is not object
spelled "Object" then? Especially since Exception's descendants are
named with the first letter of each word capitalized? I mean, in Java,
it's Object. Whereas in C++, they're quite consistent, standard stuff
are usually all lowercaps (basic_string, iostream, etc.). Python seems
to have a mix of both.

Am I right in assuming that object is object (with lower case 'o')
because it is built-in, and Exception is not? So when we write our own
classes, exceptions, etc., we should capitalize it like in Java or C#?
By the way, what's the convention for functions? It's a bit confusing
because when I see Python builtins, it seems that they follow C++ style
(e.g.: has_key, readline). So... does it mean that when I write my own
function, customarily I'd say myFunction() (or MyFunction()?)

2. I'm quite baffled that you either have try/except, or try/finally.
In Java, it is quite common to do this:

try {
    // something
} catch(AException e) {
    // handle
} catch(BException e) {
    // handle
} catch(CException e) {
    // handle
} finally {
    // whatever happens, execute this
}

It seems that since except and finally are mutually exclusive I can't
do this. So... what's the usual idiom for this?

Thanks!
Ray




More information about the Python-list mailing list