[Python-Dev] Attribute error: providing type name

Adam Olsen rhamph at gmail.com
Sun Nov 30 20:06:43 CET 2008

On Sun, Nov 30, 2008 at 11:41 AM, Filip Gruszczyński <gruszczy at gmail.com> wrote:
> This is my first message in this list, therefore I would like to say
> hello to everyone. I also hope, that I am not breaking any rules or
> guidelines for sending proposals.
> I would like to ask, if it is possible to provide type name of the
> object invoking the exception, when Attribute error is catched. It is
> done for functions, like:
> AttributeError: 'function' object has no attribute 'getValue'
> but for some objects there is only:
> AttributeError: connectToBases
> This is cool, when you know exactly what type of object cast the
> exception. But if there might be many of them, you must do one of two
> things: add print statement just before the line with the exception
> and check the type or iterate over all classes that might appear them.
> Showing the class name would solve this problem and could save a lot
> of time.

I'm sure you'll get support for this, unless it's a really
inconvenient spot that requires a gross hack to print the type name.
Post a patch on the bug tracker.

Adam Olsen, aka Rhamphoryncus

More information about the Python-Dev mailing list