28

In the Python world there are two terms which seem to be equal:

  • Stacktrace
  • Traceback

Is there any difference between the two?

2 Answers 2

20

The Stacktrace is the trace of the methods call stack, exactly as it is in the memory of the computer that is executing your program. So most recents method calls are at the top; and likely the root of the problem is at the top as well. Virtually all programming languages do it this way.

The Traceback is something Python has "invented": it's the reversed of the above. So, to find the root of your problem, you need to start reading it from the bottom, as this is apparently easier to read to pythonists. To make it clear, they have had to specify "most recent call last".

Calling "stacktrace" a "traceback" is simply wrong: a traceback is not a trace of a stack. It's a stacktrace reversed: and the "back" probably means so.

At the top of a stack, in every meaning, you have the most recent item.

2
  • 1
    traceback.extract_stack also returns the list in "traceback order": stack = StackSummary.extract(walk_stack(f), limit=limit); stack.reverse()
    – olejorgenb
    Jun 16, 2022 at 15:35
  • 2
    Yah, I agree with olejorgenb... even python's own 'extract_stack' starts at the bottom. Stacks push from bottom to top and they pop from top to bottom, so saying that one way or another 'in every meaning' is pretty arbitrary. This is an overly opinionated and needlessly scrappy way to say what you are trying to say. If we really want to get really captious, then it might be worth pointing out that processor architectures vary in whether a stack grows towards lower or higher memory addresses, so no, there is no 'in every meaning' for stack direction. Jun 24, 2022 at 12:41
13

Traceback is the idiomatic Python term (for example, the traceback module), it's often used interchangeably with stacktrace, which is used in other languages such as Java.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.