How to Print Call Stack in Python

Python is an open-source, interpretive programming language with exception-based error processing. Although Python error messages are more easily understood than error messages in other programming languages, you may need to debug your code using Python's Traceback module. Using Traceback, you can print a call stack and trace where and why your program is crashing.

Instructions

    • 1

      Open your program in your Python editor.

    • 2

      Type the following to load the Traceback module, and then press "Enter."

      import sys, traceback

    • 3

      Print the current call stack by typing the following, and then press "Enter."

      traceback.print_stack (myProgramFile)

      Starting at its invocation point, Python prints details for each call in the current stack. By looking at the output, you can see at what line an error is occurring. Python also prints the type of error.

Related Searches:

References

Comments

Related Ads

Featured