The Python Oracle

Re-inspection of values in a Traceback

Become part of the top 3% of the developers by applying to Toptal https://topt.al/25cXVn

--

Music by Eric Matyas
https://www.soundimage.org
Track title: Puzzle Meditation

--

Chapters
00:00 Question
01:23 Accepted answer (Score 5)
01:43 Thank you

--

Full question
https://stackoverflow.com/questions/5182...

Accepted answer links:
http://docs.python.org/library/inspect.h...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#python #exception #evaluate

#avk47



ACCEPTED ANSWER

Score 5


You can use inspect module :

try:
    foo()
except AssertionError, e:
    import inspect
    previous_trace = inspect.trace()[1]
    frame = previous_trace[0]
    print 'value of a, b:', inspect.getargvalues(frame).locals

See http://docs.python.org/library/inspect.html#inspect.getargvalues