More informative AttributeError message?

Huaiyu Zhu hzhu at localhost.localdomain
Wed Aug 16 16:13:22 EDT 2000


I would suggest that the traceback of AttributeError also indicate the class
of the object.

For example, an exception traceback like
  File "...", line 135, in get_data
    col = col.trans(tr)
    AttributeError: trans

is often caused by some previous error that makes the object col not what I
thought it was.  This can often be simply debugged by adding

print col, print col.__class__

immediately preceding the offending code.  But if the actual error is
located in a piece of code still undergoing a lot of changes, it is often
convenient to keep the print statement for a while.  But it would clutter
output when there is no error, and I have to remember to remove it when
things gets stable.

Would it be better for the error message to be

    AttributeError: trans (for object col of class whatever)

I don't see any down side to this, except that if the attribute __class__ is
itself missing, which could be handled separately.

Huaiyu




More information about the Python-list mailing list