naive question about tracebacks

Tim Peters tim.one at comcast.net
Wed Feb 19 19:36:56 EST 2003


[Andrew Koenig]
> >>> def foo():
> ...     bar()
> ...
> >>> def bar():
> ...     baz()
> ...
> >>> foo()
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
>   File "<stdin>", line 2, in foo
>   File "<stdin>", line 2, in bar
> NameError: global name 'baz' is not defined
>
>
> If the most recent call is last, why is it called a traceback
> instead of a traceforward?

Guido's genius for naming things:  Python's traceback module's doc is
google's #1 hit for "traceback", of 100,000+.  Guido just knew that
traceforward wouldn't catch on.

> More generally, why is the most recent call last?  Is it because
> of the presumption that the earlier calls will scroll off the
> top of the screen?

I expect only Guido knows for sure, and I don't recall that it was ever
asked before.  In channeling mode, my guess is that he didn't think it
mattered much, and at the time a traceback is printed the code has a pointer
to a singly-linked list of traceback objects (one per frame involved in the
traceback), most-recent last.  So printing least-to-most recent is simplest.

I'll take your scrolling rationale as "a good reason", though!  For example,
Win9x DOS boxes don't have scrollable history, and all but the most recent
50 lines (provided you've made the box the largest it can be made) scroll
away forever.






More information about the Python-list mailing list