save it as errorexample pydef spam()bacon(def bacon()raise exception('this is the error message 'spam(when you run errorexample pythe output will look like thistraceback (most recent call last)file "errorexample py"line in spam(file "errorexample py"line in spam bacon(file "errorexample py"line in bacon raise exception('this is the error message 'exceptionthis is the error message from the tracebackyou can see that the error happened on line in the bacon(function this particular call to bacon(came from line in the spam(functionwhich in turn was called on line in programs where functions can be called from multiple placesthe call stack can help you determine which call led to the error python displays the traceback whenever raised exception goes unhandled but you can also obtain it as string by calling traceback format_exc(this function is useful if you want the information from an exception' traceback but also want an except statement to gracefully handle the exception you will need to import python' traceback module before calling this function for exampleinstead of crashing your program right when an exception occursyou can write the traceback information to text file and keep your program running you can look at the text file laterwhen you're ready to debug your program enter the following into the interactive shellimport traceback tryraise exception('this is the error message 'excepterrorfile open('errorinfo txt'' 'errorfile write(traceback format_exc()errorfile close(print('the traceback info was written to errorinfo txt ' the traceback info was written to errorinfo txt