More informative AttributeError message?

Penfold spam at spam.com
Wed Aug 16 19:21:18 EDT 2000


Huaiyu Zhu <hzhu at localhost.localdomain> wrote in message
news:slrn8pltnb.13a.hzhu at rocket.knowledgetrack.com...
> I would suggest that the traceback of AttributeError also indicate the
class
> of the object.
[gratuitous snip]
Even better, would be something more along the lines of
AttributeError: %attribute% (for object of type %typename% [Instance of
%classname%])

Since you can often cause these by having the wrong type also.  You surely
can't get the name of the
offending object in the exception message as you suggest, since that assumes
the interpreter knows the
current name binding of the object its trying to do an attribute access on,
and I imagine all the
interpreter/ceval cares about is that its the item nearly on the top of the
stack !!

Futhermore of course, it might not have a name binding at all, since it
could well just be a temporary eg ([1,2] + [3,4]).blah

But I agree, this would be a *much more useful message*, better than having
to print it out, or drop into pdb to check it [the alternative solution,
which is always handy, is to make all your python scripts take an option
which when true wraps your "main" function in a try: catch: and
automatically drops into pdb to analyse the exception].


Have a nice day!

Des.

> Would it be better for the error message to be
>
>     AttributeError: trans (for object col of class whatever)
>






More information about the Python-list mailing list