Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7769887
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:16:14+00:00 2026-06-01T16:16:14+00:00

I am confused about the difference between two objects: the list of frames returned

  • 0

I am confused about the difference between two objects:

  • the list of frames returned by inspect.trace() while an exception is being handled
  • the traceback returned by sys.exc_info()[2] (or passed in the call to sys.excepthook)

Do the two objects contain the same information, just organized into a different data structure? If not, what one has that the other doesn’t?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T16:16:15+00:00Added an answer on June 1, 2026 at 4:16 pm

    From the documentation of inspect.trace:

    inspect.trace([context])

    Return a list of frame records for the stack between the current frame and the frame in which an exception currently being handled was raised in. The first entry in the list represents the caller; the last entry represents where the exception was raised.

    which suggests that it provides a nice way to slice and dice which frames from sys.exc_info()[2] you get.

    Which, if you look at the source:

    def trace(context=1):
        """Return a list of records for the stack below the current exception."""
        return getinnerframes(sys.exc_info()[2], context)
    

    (identical for 3.2 or 2.7), is exactly what it does, but it passes it through getinnerframes, which annotates it with some useful information, per the docstring:

    Get a list of records for a traceback’s frame and all lower frames.

    Each record contains a frame object, filename, line number, function
    name, a list of lines of context, and index within the context.

    And, since I’m curious about what that actually means:

    import sys
    import inspect
    from pprint import pprint
    
    
    def errorer():
        raise Exception('foo')
    
    def syser():
        try:
            errorer()
        except Exception, e:
            tb = sys.exc_info()[2]
            print tb.tb_frame
            print tb.tb_lasti
            print tb.tb_lineno
            print tb.tb_next
    
    def inspecter():
        try:
            errorer()
        except Exception, e:
            pprint(inspect.trace())
    

    Which, when called from the prompt, while recalling that many of those fields and objects have easy-to-find definitions:

    >>> syser()
    <frame object at 0x1441240>
    6
    10
    <traceback object at 0x13eb3b0>
    >>> inspecter()
    [(<frame object at 0x14a5590>,
      '/tmp/errors.py',
      22,
      'inspecter',
      None,
      None),
     (<frame object at 0x14a21b0>,
      '/tmp/errors.py',
      8,
      'errorer',
      None,
      None)]
    

    (line numbers jumped around because I messed with formatting)

    inspect.trace() is obviously a bit nicer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm confused about the difference between these two things: $env:path And function path {$env:path}
I am quite confused about the difference between an index on table and index
I am a bit confused about the difference between Silverlight and Expression Blend. From
I am confused about which is which. Can someone explain the difference between the
I am bit confused about the difference between the usage of std::remove algorithm. Specifically
I am little confused about the difference between containers and collections. I read about
I am really confused about the difference between GOF and GRASP patterns? even both
I am confused about the difference between function calls via . and via :
I'm a bit confused about the difference between a facebook canvas application and a
I'm confused about the differences between these two special folders. Here's a code snippet

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.