Re: ???: telling tracebacks to stop

Steven D. Majewski (sdm7g@elvis.med.virginia.edu)
Wed, 23 Mar 1994 17:12:48 -0500

Oops! Jaap is correct.

It's sys.exc_traceback, et. al, NOT sys.last_traceback !

When I did :

>>> 1 + ''
Traceback (innermost last):
File "<stdin>", line 1
TypeError: number coercion failed
>>> errt()
<function errt at 200740b8>
<function f at 20074018> (1, 2)
<function g at 20074038> (1, 2)
Traceback (innermost last):
File "<stdin>", line 1
TypeError: number coercion failed
<traceback object at 2006a348>
>>>

i.e. I got the PREVIOUS error's traceback, not the current one.

---

I didn't understand why which end of the list was to be chopped was such a big problem for Thomas, until I tried to linearize the linked list:

def linearize( head, link_attr ): list = [] obj = head while obj: list.append( obj ) obj = getattr( obj, link_attr ) return list

traces = linearize( traceback ) for tb in traces : print tb.tb_frame.f_code.co_name

- which works fine, but when I tried to chop off the tail:

>>> tbs[-2] <traceback object at 20085558> >>> tbs[-2].tb_next <traceback object at 200845a8> >>> tbs[-2].tb_next = None Traceback (innermost last): File "<stdin>", line 1 TypeError: object has read-only attributes >>>

I suddenly remembered that tracebacks are read-only objects.

While on the subject of read_only objects: There were a few bugs in the hack I posted to add a 'func_doc' r/w attribute to functions. If anyone wants a better version, let me know. However, one of the things learned from my describe function, using the linecache.getline() function to grab documentation from the file, is that a separate func_doc attribute is probably not necessary. We could, instead, just create a dictionary mapping functions to doc strings, and use something like describe to build the strings.

- Steve Majewski (804-982-0831) <sdm7g@Virginia.EDU> - UVA Department of Molecular Physiology and Biological Physics